Sax String Parsing

Hi. I want to parse a String that has an xml format with Sax according to a specific scema using xerces. I've written the following code:
public void parse(String rr) throws Exception {
SAXReader reader = new SAXReader();
reader.setValidation(true);
// specify the schema to use
try{
reader.setProperty(
"C:\\Documents and Settings\\Don Jiovanni\\jbproject\\project",
"myxsd.xsd"); //this is my xsd
}catch(Exception e){ System.out.println("Cause: "+e.getMessage()); }
// add an error handler which turns any errors into XML
XMLErrorHandler errorHandler = new XMLErrorHandler();
reader.setErrorHandler( errorHandler );
try{
reader.read(rr); //pase the string
}catch(Exception ex){System.out.println("Cause: "+ex.getMessage());}
//output the errors as XML
XMLWriter writer = new XMLWriter( OutputFormat.createPrettyPrint() );
writer.write( errorHandler.getErrors() );
What i get is 2 exceptions:
for the first try...catch:
"Property: C:\Documents and Settings\Don Jiovanni\jbproject\project"
and for the second one:
"The filename, directory name, or volume label syntax is incorrect"
Any help...?

loadGame( new StringReader( someBuffer ) );
public void loadGame(Reader reader)
     throws ParserConfigurationException, SAXException, IOException, NullPointerException  {
          SAXParserFactory factory = SAXParserFactory.newInstance();
          SAXParser saxParser = factory.newSAXParser();
          saxParser.parse( new InputSource(reader), defaultLoadHandler );
}

Similar Messages

  • XML Validation using XDK SAX/DOM Parser

    Hello,
    I am trying to validate xml against xsd using SAX/DOM parser, both the files are stored as CLOB column in the database. I have the requirement to report all the validation errors and based on some helpful advice/code from the earlier posts in this forum, I have used the following code to validate and report the errors.
    The code works fine but for large files it never goes beyond a certain number of errors i.e. getNumMessages() (XMLParseException) never returns value greater than 100 and thus limits the output of the validation errors. Any pointers to suggest change in code or an alternative will be extremely helpful.
    Datebase Version : Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED <> as package <package name>;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import java.sql.SQLException;
    import oracle.sql.CLOB;
    import oracle.xml.parser.schema.*;
    import oracle.xml.parser.v2.*;
    import org.w3c.dom.*;
    public class XMLSchemaVal
    public static String validate(CLOB xmlDoc, CLOB xsdDoc)
    throws Exception
    //Build Schema Object
    XSDBuilder builder = new XSDBuilder();
    Reader xsdInUnicodeFormat = xsdDoc.getCharacterStream();
    XMLSchema schemadoc = (XMLSchema)builder.build(xsdInUnicodeFormat, null);
    //Build XML Object
    Reader xmlInUnicodeFormat = xmlDoc.getCharacterStream();
    // Genereate the SAX
    SAXParser saxparser_doc = new SAXParser();
    // Set Schema Object for Validation
    saxparser_doc.setXMLSchema(schemadoc);
    saxparser_doc.setValidationMode(XMLParser.SCHEMA_VALIDATION);
    saxparser_doc.setPreserveWhitespace (true);
    String returnValue;
    try {
    saxparser_doc.parse (xmlInUnicodeFormat);
    returnValue = "The input XML parsed without errors.\n";
    catch (XMLParseException se) {
    returnValue = "Parser Exception: ";
    for (int i=0 ; i < se.getNumMessages(); i++)
    returnValue += "<LN: " + se.getLineNumber(i) + ">: " + se.getMessage(i);
    //returnValue = "Parser Exception: " + se.getNumMessages();
    catch (Exception e) {
    returnValue = "NonParserException: " + e.getMessage();
    return returnValue;
    Function to call the above utility from PL/SQL
    CREATE OR REPLACE FUNCTION F_XMLSCHEMAVALIDATION (P_XML IN clob ,P_XSD IN clob) RETURN VARCHAR2 IS
    LANGUAGE JAVA NAME XMLSchemaVal.validate(oracle.sql.CLOB,oracle.sql.CLOB) return java.lang.String';
    Thanks.

    Got the answer !!!
    NetBeans it self support generation of dtd file based on XML file.
    Open XML file and right click on the code block. Select option to generate dtd file.
    This is the drtd file it has generated..
    <?xml version='1.0' encoding='UTF-8'?>
    <!--- Put your DTDDoc comment here. -->
    <!ELEMENT book (person)*>
    <!--- Put your DTDDoc comment here. -->
    <!ELEMENT person (age|last|first)*>
    <!--- Put your DTDDoc comment here. -->
    <!ELEMENT first (#PCDATA)>
    <!--- Put your DTDDoc comment here. -->
    <!ELEMENT last (#PCDATA)>
    <!--- Put your DTDDoc comment here. -->
    <!ELEMENT age (#PCDATA)>

  • Sax XML Parser? URLDecoder.decode bad in applet? Explorer Browser jvm?

    Ok, here it goes folks, I have a serious problem with Explorers jvm, I'm developing using jdk 1.3.1 to write swing applets, in anyevent little functions that I use will not work with Explorers Browser, for example, the Explorer JVM understands the Vector addElement function, but not the Vector add function? Also, It doesn't recognize the HashMap class? Ok, is there anyway to control the JVM used with Explorer? Ok, but here goes my real question?
    I am writing an applet/servlet that interfaces with an oracle database. The data is returned in the form of xml. We are using the Sax XML parser interface. The parser code previously in the servlet(server side) and worked fine, but I've now moved the parsing code to the applet side, however, it seems to not want to work on the applet side. It simply hangs? I think it's a jvm issue, I've been getting many hangs with seemingly standard classes and methods, such as URLDecoder.decode(). Anyone else run into this problem using the Sax XML Parser, I have no idea what classes in the SAX Parser could be giving us a problems, or if that is even my issue. Anyone else using SAX XML parsing in an applet with Explorer 5.5. or 5.0, please let me know, if you've had issues?
    Sorry, to be so long winded, and not explaining the problem very well.

    First, get Sun's Java Plug-in from http://java.sun.com/products/plugin/index-1.4.html
    and read up on how to make your browser use it instead.

  • Oracle date string parser

    I really want that oracle can change their command parser engine to be smart enough especially for date string parsing.
    currently the engine will throw error when we type a date string as (for example) '10/10/10', while this command can be accepted in MS-SQLServer.

    AMaster wrote:
    i have stored three numbers in three different variables and want to join all of them to concatanate:
    http://docs.oracle.com/cd/B19306_01/server.102/b14200/operators003.htm
    make a date string , kindly help me with this.
    Edited by: AMaster on Sep 6, 2012 4:12 AMto_date:
    http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions183.htm
    How to ask a question:
    SQL and PL/SQL FAQ

  • MS IE toStaticHTML String Parsing Cross-Site Scripting Vulnerability alarms

    Hi,
    I was wondering if someone else has noted an increase in false positives concerning the following 2 events:
    - Microsoft Internet Explorer toStaticHTML String Parsing Cross-Site Scripting  Vulnerability
    - Microsoft Office Excel Ghost Record Parsing Arbitrary Code Execution Vulnerability
    Obvisouly I see these events because the signature has been introduced recently!!!
    But I wonder if these alarms I'm getting are genuine (and I have a big problem), or if the signature needs to be 'tuned' by Cisco to be a bit less sensitive?
    Anyone has experienced something similar or can shed a light?
    Thanks,
    seb.

    Hello Seb,
    Since I don't have the entire transmission, I can't tell what exactly is commented out in regard to the tags, but the data appears to look something like below.
    e){  
      //v3.0..   
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
      if (restore) selObj.selectedIndex=0;
    //-->
    @td  
    img{display: block;}
    @import url("p7tp/p7tp_01.css
    With 30419 being related to CVE-2010-3324, I assume the signature is firing due to some match variation of the fact that @import and the tags are showing up in a response from your web server. The toStaticHTML method should remove tags, but the vulnerability is causing that mechanism to fail.
    The oBot User-Agent caught my eye. Google returns several pages to the effect of oBot being a:
    "German spider from Cobion, now part of Internet Security Systems. Scans the web for their clients looking for copyright infringement."
    I'm not sure what benefit this search bot would receive from injecting Javascript into the response.
    I'll forward the capture data to our sig team to confirm whether this should be a legitimate match.
    Thank you,
    Blayne Dreier
    Cisco TAC Escalation Team
    **Please check out our Podcasts**
    TAC Security Show: http://www.cisco.com/go/tacsecuritypodcast
    TAC IPS Media Series: https://supportforums.cisco.com/community/netpro/security/intrusion-prevention?view=tags&tags=tac_ips_media_series

  • Help With String parsing

    Hey guys,
    I need some help with String Parsing. i hope experts here will help me.
    i'm reading a text file and getting data as String in this format
    *ABR, PAT MSSA        2009       7001    B   ABC       Y
    *VBR, SAT ZSSA        2008       5001    A   CED       N
    *ABC, AAT CSSA        5008       001     A   AZX       N
    *CBC, CAT FSSA        308        5001    A   XCV       N
    Now from following lines i have to extract Number data i.e. 2009 and 7001 from 1st line. 2008 and 5001 from 2nd line and so on.
    Can anyone pls suggest me any way to get the data that i want from these Strings
    Thanks for your time to read this.
    Regards,
    sam

    Thanks for the reply
    Data length can vary. ABR, PAT is the last name, First Name of the Users.
    it can be following or any other combination. i just need 2 set of numbers from the complete line rest i can ignore. Any other way to get that
    *ABRaaassd, PATfffff MSSA 2009 7001 B ABC Y
    *VBRaa, SATaa ZSSA 2008 5001 A CED N
    *ABC, AAT CSSA 5008 001 A AZX N
    *CBC, CAT FSSA 308 5001 A XCV N                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • SAX XML Parser problem

    Hi,
    I have a standard .xml file and a file called TemplateContentHandler that parses the info in the xml doc but there is an error in it. See below:
    TemplateContentHandler.java
    if ( strElementName.equals( TemplateConstants.RNC_Module_LDN_TU1 ) ) {
                timingUnit1TagExistInDefaultTemplateFile = true;
                System.err.println("timingUnit1TagExistInDefaultTemplateFile for TU1 == "+timingUnit1TagExistInDefaultTemplateFile);
                System.err.println("strValue for TU1 == "+strValue);
                tTemplate.setRNC_Module_LDN_TU1( strValue );
                Trace.exit();
                return;
            if ( strElementName.equals( TemplateConstants.RNC_Module_LDN_TU2 ) ) {
                timingUnit2TagExistInDefaultTemplateFile = true;
                System.err.println("timingUnit2TagExistInDefaultTemplateFile for TU2 == "+timingUnit2TagExistInDefaultTemplateFile);
                System.err.println("strValue for TU2 == "+strValue);
                tTemplate.setRNC_Module_LDN_TU2( strValue );       
                Trace.exit();
                return;
            }DefaultTemplate
    <RNC_Module_LDN_TU2>ManagedElement=1,Equipment=1,Subrack=MS,Slot=5,PlugInUnit=1</RNC_Module_LDN_TU2>
    <RNC_Module_LDN_TU1>ManagedElement=1,Equipment=1,Subrack=MS,Slot=4,PlugInUnit=1</RNC_Module_LDN_TU1>
    OutPut
    root@atrcus13> timingUnit2TagExistInDefaultTemplateFile for TU2 == true
    strValue for TU2 == ManagedElement=1,Equipment=1,Subrack=MS,Slot=5,PlugInUnit=1
    timingUnit1TagExistInDefaultTemplateFile for TU1 == true
    strValue for TU1 == ManagedElement=1,Equipment=1,Subrack=MS,SlottimingUnit1TagExistInDefaultTemplateFile for TU1 == true
    strValue for TU1 == =4,PlugInUnit=1
    as you can see it parses the Tag <RNC_Module_LDN_TU1> twice and splits it in2 pieces. does anyone know why this is? Also I added a dirty hack whcih works:
    private int timimngUnit1Tagcounter = 0;
        private int timimngUnit2Tagcounter = 0;
    if( timimngUnit1Tagcounter == 0) {
                    tempTU1 = strValue;
                    timimngUnit1Tagcounter++;
                    Trace.message("FIRST TIME STRVALUE === "+strValue);
                    tTemplate.setRNC_Module_LDN_TU1( strValue );
                else {
                    Trace.message("SECOND TIME STRVALUE === " + tempTU1+strValue);
                     tTemplate.setRNC_Module_LDN_TU1( tempTU1+strValue );
                     timimngUnit1Tagcounter = 0;
                }but now the parser is screwing up other tags in the file; anyone have any ideas?
    Thanks,
    Vinnie

    In which method is the code you've posted called?
    Given your results, I'd suspect that it's in characters, and strValue is a string created from the character data passed in.
    in that case, read
    http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/ContentHandler.html#characters(char[],%20int,%20int)
    in particular
    The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.
    The accepted pattern of use where you want to process all character data between tags in one go is to use a StringBuffer to acculmulate the characters, then process them in the following endElement or beginElement method.
    Pete

  • SAX error parsing by element. need help!

    I am trying to develop a small method to that can parse an xml file and return an elements value. I got some code to build a SAXHandler. I have build the SAXHandler and have compiled it no problem.
    import java.io.*;
    import java.util.Hashtable;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    public class SAXHandler extends DefaultHandler {
    private Hashtable table = new Hashtable();
    private String currentElement = null;
    private String currentValue = null;
    public void setTable(Hashtable table) {
    this.table = table;
    public Hashtable getTable(){
    return table;
    public void startElement(String tag, Attributes attrs)
    throws SAXException {
    currentElement = tag;
    public void characters(char[] ch, int start, int length)
    throws SAXException {
    currentValue = new String(ch, start, length);
    public void endElement(String name) throws SAXException {
    if (currentElement.equals(name)) {
    table.put(currentElement, currentValue);
    I am using the following code to read the file in and parse it.
    public String getXMLElement(){
    try {
    File xmlFile = new File(appDataFile);
    FileReader xmlRead = new FileReader(xmlFile);
    XMLReader xmlParser;
    SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    SAXHandler handler = new SAXHandler();
    sp.parse(new InputSource(xmlRead), handler);
    i am recieving the following error when I try to run the servlet
    javax.servlet.ServletException: Cannot allocate servlet instance for path /JDtrack/servlet/JDTrack
    what makes this wierd is that is i take out the line
    sp.parse(new InputSource(xmlRead), handler);
    I do not get the error.
    I am newer to java and could use all the help I can get
    thanks.

    A few things to try to help identify the problem:
    -Create and InputSource before parsing the file. If the InputSource cannot be created, there may be a problem with accessing the file from your servlet.
    -Write a quick program to do the same thing from an application. If you can do this outside the servlet container, it may be a problem from running inside the servlet container.
    -The code you listed is in a try block, however the catch block is not listed. If you are not already doing so, place debug message (to console or log) from inside each catch block. If an exception is thrown but not handled corrrectly, the servlet container may just throw a ServletException.
    Hope this helps.

  • How to use sax xml parser

    hi was wondering if someone could give me an example on how to use sax
    and a document handler and explain a bit

    to use sax parsers you need basically to extends handlerBase wich will force you to have the 3 following methods
    // imports for the sax portion of the manager,
    // the portion that will permit the interpretation of
    import com.sun.xml.parser.Resolver;
    import org.xml.sax.*;
    import org.xml.sax.helpers.ParserFactory;
    public class XMLManager extends HandlerBase
    private String currentElement = null; //current element name for parsing
    * Default constructor
    public XMLManager()
    /*SAX METHODS*/
    * This method is called when the SAX parser encounters an open element
    * tag. Must remember which element tag was just opened (so that the
    * characters(..) method can do something useful with the data that is
    * read by the parser.
    public void startElement(String name,AttributeList atts){
    if( name.equalsIgnoreCase("MY XML TAG NAME") )
    currentElement = "MY XML TAG NAME";
    //then do stuff for that type of tag
    * This method is called when the SAX parser encounters a close element
    * tag. If the message tag is closed it means the message is valid and ready
    * to be treated
    public void endElement(String name){
    currentElement = "";
    * This method is called when the SAX parser encounters #PCDATA or CDATA.
    * It is important to remember which element tag was just opened so that
    * this data can be put in the right object or variable.
    * Also the start index and length integer must be used to retrieve only
    * a portion of the data stored in the char[]
    * This section will only contain treatment for tags wich have content
    * between start and end tags
    public void characters(char ch[],int start,int length){
    //dont read ch[] , use the
    //range provided by the SAX parser.
    String value = new String(ch,start ,length);
    Once you have defined these 3 methods, define a method called for example parseIt(String mss) wich will contain the following code to parse the content of a string mss, a string containing xml data
    try
    //create an InputSource from the XML source received
    StringReader r = new StringReader(mss);
    InputSource is = new InputSource( r );
    //create a SAX parser using SAX interfaces and classes
    String parserClassName = "com.sun.xml.parser.Parser";
    org.xml.sax.Parser parser = org.xml.sax.helpers.ParserFactory.makeParser(parserClassName);
    //create document handler to do something useful
    //with the XML document being parsed by the parser.
    parser.setDocumentHandler(this);
    parser.parse(is);
    catch(Throwable t){System.out.println(t);t.printStackTrace();}
    you can't fail with this ;)

  • SAX XML Parsing and Garbage Collection

    I'm writing an XML parser that is running extremely slow while parsing large documents, I believe due to garbage collection. The implementation just overloads the DefaultHandler and hands that to a SAX Parser. This works fine on 2500 line XML document, taking on average a second or two, but becomes untennable when the document size is increased by a factor of 10 (often taking 5+ minutes).
    I come from a C++ background and haven't dealt with automatic garbage collection at an expert level, so I'd appreciate any help. Below is a snapshot garbage collection done while a 25000 line document being parsed. It looks to me as the young objects are staying small, but older objects are going between 13M and 90M and back again. Is that what's happening? Can anyone give me leads as to what to look? Thanks in advance.
    [GC [DefNew: 6234K->0K(7168K), 0.0057359 secs] 15517K->13022K(101696K), 0.0057907 secs]
    [GC [DefNew: 6235K->0K(7168K), 0.0057748 secs] 19257K->16762K(101696K), 0.0060357 secs]
    [GC [DefNew: 6235K->0K(7168K), 0.0023584 secs] 22997K->18009K(101696K), 0.0024123 secs]
    [GC [DefNew: 6236K->0K(7168K), 0.0040785 secs] 24245K->20502K(101696K), 0.0041315 secs]
    [GC [DefNew: 4990K->0K(7168K), 0.0041025 secs] 25492K->22996K(101696K), 0.0041544 secs]
    [GC [DefNew: 4990K->0K(7168K), 0.0041486 secs] 27987K->25491K(101696K), 0.0042022 secs]
    [GC [DefNew: 4991K->0K(7168K), 0.0040782 secs] 30481K->27985K(101696K), 0.0041299 secs]
    [GC [DefNew: 4991K->0K(7168K), 0.0040935 secs] 32976K->30479K(101696K), 0.0046294 secs]
    [GC [DefNew: 4991K->0K(7168K), 0.0041433 secs] 35471K->32974K(101696K), 0.0041958 secs]
    [GC [DefNew: 4992K->0K(7168K), 0.0041114 secs] 37966K->35469K(101696K), 0.0041634 secs]
    [GC [DefNew: 6240K->0K(7168K), 0.0024190 secs] 41709K->36717K(101696K), 0.0024729 secs]
    [GC [DefNew: 6240K->0K(7168K), 0.0041377 secs] 42957K->39212K(101696K), 0.0041972 secs]
    [GC [DefNew: 4993K->0K(7168K), 0.0041234 secs] 44205K->41707K(101696K), 0.0041762 secs]
    [GC [DefNew: 4993K->0K(7168K), 0.0042827 secs] 46701K->44203K(101696K), 0.0046299 secs]
    [GC [DefNew: 4994K->0K(7168K), 0.0043195 secs] 49197K->46699K(101696K), 0.0043751 secs]
    [GC [DefNew: 4994K->0K(7168K), 0.0042740 secs] 51693K->49195K(101696K), 0.0043293 secs]
    [GC [DefNew: 4995K->0K(7168K), 0.0042044 secs] 54190K->51692K(101696K), 0.0042575 secs]
    [GC [DefNew: 4995K->0K(7168K), 0.0042237 secs] 56686K->54188K(101696K), 0.0042762 secs]
    [GC [DefNew: 4996K->1K(7168K), 0.0040036 secs] 59183K->56685K(101696K), 0.0040550 secs]
    [GC [DefNew: 4996K->1K(7168K), 0.0042095 secs] 61680K->59182K(101696K), 0.0045992 secs]
    [GC [DefNew: 4997K->1K(7168K), 0.0042193 secs] 64178K->61679K(101696K), 0.0042715 secs]
    [GC [DefNew: 4997K->1K(7168K), 0.0042301 secs] 66675K->64176K(101696K), 0.0042818 secs]
    [GC [DefNew: 4997K->1K(7168K), 0.0042726 secs] 69173K->66674K(101696K), 0.0043251 secs]
    [GC [DefNew: 4998K->1K(7168K), 0.0042564 secs] 71671K->69172K(101696K), 0.0043084 secs]
    [GC [DefNew: 4998K->1K(7168K), 0.0040301 secs] 74169K->71669K(101696K), 0.0040812 secs]
    [GC [DefNew: 4999K->1K(7168K), 0.0042656 secs] 76668K->74168K(101696K), 0.0047255 secs]
    [GC [DefNew: 4999K->1K(7168K), 0.0043100 secs] 79166K->76666K(101696K), 0.0043737 secs]
    [GC [DefNew: 5000K->1K(7168K), 0.0043492 secs] 81665K->79165K(101696K), 0.0044034 secs]
    [GC [DefNew: 5000K->1K(7168K), 0.0043165 secs] 84164K->81664K(101696K), 0.0043693 secs]
    [GC [DefNew: 5001K->1K(7168K), 0.0044196 secs] 86663K->84163K(101696K), 0.0044735 secs]
    [GC [DefNew: 5001K->1K(7168K), 0.0044439 secs] 89163K->86662K(101696K), 0.0044967 secs]
    [GC [DefNew: 5001K->1K(7168K), 0.0043983 secs] 91662K->89161K(101696K), 0.0045313 secs]
    [GC [DefNew: 5002K->1K(7168K), 0.0043422 secs] 94162K->91661K(101696K), 0.0043944 secs]
    [GC [DefNew: 5002K->1K(7168K), 0.0044223 secs] 96662K->94160K(101696K), 0.0044757 secs]
    [GC [DefNew: 5002K->1K(7168K), 0.0048545 secs][Tenured: 96659K->9291K(97032K), 0.0863445 secs] 99162K->9291K(104200K), 0.0913954 secs]

    I don't think I'm creating megabytes of data, not using hashes or other expandable arrays. I've copied and pasted some code from my overriding of a DefaultHandler to give better definition to the problem.
    I'm working with TPTP right now as a profiler. Are there any others you'd recommend?
         public void startElement(String uri, String localname, String qName, Attributes attribs)
         throws SAXException
              if(qName.equals("Line"))
                   attributes = attribs;
              else if(qName.equals("Note"))
                   attributes = attribs;
              else if(qName.equals("Selection"))
                   String idValue = attribs.getValue("id");
                   String oValue = attribs.getValue("off");
                   String lValue = attribs.getValue("len");
                   if(idValue != null && oValue != null && lValue != null)
                        if(isImport)
                             issueSelectionContainer.addUnloadedSelection(Integer.parseInt(idValue), Integer.parseInt(oValue), Integer.parseInt(lValue));
                        else
                             issueSelectionContainer.addSelection(Integer.parseInt(idValue), Integer.parseInt(oValue), Integer.parseInt(lValue));
              else if(qName.equals("Issue"))
                   attributes = attribs;
              if(qName.equals("IsFinal"))
                   isFinal = true;
         public void endElement(String uri, String localname, String qName)
         throws SAXException
              if(textElement.length() > 0)
                   if(qName.equals("Line"))
                        String qmValue = attributes.getValue("qm");
                        String lnValue = attributes.getValue("ln");
                        String pgValue = attributes.getValue("pg");
                        boolean qm = (qmValue != null && qmValue.equalsIgnoreCase("true"));
                        short ln = (lnValue != null) ? Short.parseShort(lnValue) : 0;
                        short pg;
                        if(pgValue != null)
                             pg = Short.parseShort(pgValue);
                             page = pg;
                        else
                             pg = page;
                        lineContainer.addLine(textElement + '\n', ln, pg, qm, null);
                   else if(qName.equals("Note"))
                        String lnValue = attributes.getValue("line");
                        if(lnValue != null)
                             int line = Integer.parseInt(lnValue);
                             try
                                  lineContainer.getLine(line).setNote(textElement);
                             catch (IndexOutOfBoundsException e)
                                  throw new SAXException("XML/Data mismatch.  Note on line \"" + line + "\" out of \"" + lineContainer.lineCount() + "\" lines", e);
                   else if(qName.equals("Issue") && isImport)
                        String idValue = attributes.getValue("id");
                        String cValue = attributes.getValue("color");
                        if(idValue != null && cValue != null)
                             issueSelectionContainer.addUnloadedIssueSelection(Integer.parseInt(idValue), new Color(Integer.parseInt(cValue)), textElement);
                   else if(qName.equals("Name"))
                        name = textElement;
                   else if(qName.equals("Description"))
                        description = textElement;
                   else if(qName.equals("CreationDate"))
                        date = getCalendarFromString(textElement);
                   textElement = "";
                   attributes = null;
         public void characters(char buf[], int offset, int len)
        throws SAXException
              textElement = new String(buf, offset, len);
        }

  • XML string parsing

    Is there any class method to parse an XML string into tags and contents?
    I have a response in XML and would like to read a tags contents.
    Thanks

    Hi KP,
    look at the iXML library. http://help.sap.com/saphelp_nw04/helpdata/en/47/b5413acdb62f70e10000000a114084/frameset.htm
    Depending what release you are developing on you might also want to look at SImple Transformations.
    Cheers
    Graham

  • Any bright ideas? (string parsing question)

    Hi,
    I need to put together some static methods for parsing and comparing strings in different formats. I've written the skeleton methods with some nice comments below:
    public class ParsingTools {
        * This method should be able to convert a string that contains
        * a date in an arbitrary format, to a java.util.date.
        * E.G. '10.12.1998 4:15 AM', 'Jan 6th 1984', '1/01/00'
        * '24th Feb 1975 0530hrs'.  The boolean 'usa' parameter indicates
        * whether its usa style dates: mm/dd/yyyy, instead of dd/mm/yyyy.
        * @param inputDate
        * @param usa
        * @return
       public static Date parseStringDate(String inputDate, boolean usa){
          Date outputDate = null;
          return outputDate;
        * This method should be able to convert strings like:
        * "$10,000.45" to the double 10000.45, or even:
        * "'x=$$254,433,344.003'" to 254433344.00.  All kinds of
        * extraneous characters could be received, this method extracts
        * and returns the number part.
        * @param inputString
        * @return
       public static double parseMoneyString(String inputString){
          double outputDouble = 0.0;
          return outputDouble;
        * This method takes two strings, the first of which is compared
        * to the second to see if they are a close enough match.
        * E.G. " exerci$ed_" compared with "EXERCISED" should return
        * true, but "elephant" compared with "EXERCISED" should return
        * false.
        * @param inputString
        * @param compareString
        * @return
       public static boolean matchToString(String inputString,
                                           String compareString){
          boolean matches = false;
          return matches;
    }Ok, the getting the double from the money string one is easy, just search through the string until you find some numbers, and strip out any commas.
    If anyone has any ideas on a clever way of doing the date parsing, and the string compare one, or knows of existing methods to do these, I'd love to hear about it.
    Many long hours of messing around with string operations await me otherwise!
    Thanks

    I need to put together some static methods for
    parsing and comparing strings in different formats.
    I've written the skeleton methods with some nice
    e comments below:Why isn't java.text.DateFormat good enough for you? I'll bet they do it better.
    I'd use Locale for currencies.
    This is a case where stuff that's already available to you should be preferred. Why write your own when someone else has already done it better? You don't have to maintain it, either. JMO, of course.
    >
    public class ParsingTools {
    * This method should be able to convert a string
    ring that contains
    * a date in an arbitrary format, to a
    to a java.util.date.
    * E.G. '10.12.1998 4:15 AM', 'Jan 6th 1984',
    84', '1/01/00'
    * '24th Feb 1975 0530hrs'.  The boolean 'usa'
    usa' parameter indicates
    * whether its usa style dates: mm/dd/yyyy,
    yyy, instead of dd/mm/yyyy.
    * @param inputDate
    * @param usa
    * @return
    public static Date parseStringDate(String
    ing inputDate, boolean usa){
    Date outputDate = null;
    return outputDate;
    * This method should be able to convert strings
    ings like:
    * "$10,000.45" to the double 10000.45, or even:
    * "'x=$$254,433,344.003'" to 254433344.00.  All
    All kinds of
    * extraneous characters could be received, this
    this method extracts
    * and returns the number part.
    * @param inputString
    * @return
    public static double parseMoneyString(String
    ing inputString){
    double outputDouble = 0.0;
    return outputDouble;
    * This method takes two strings, the first of
    t of which is compared
    * to the second to see if they are a close enough
    ough match.
    * E.G. " exerci$ed_" compared with "EXERCISED"
    SED" should return
    * true, but "elephant" compared with "EXERCISED"
    SED" should return
    * false.
    * @param inputString
    * @param compareString
    * @return
    public static boolean matchToString(String
    ing inputString,
    String
    String
    String compareString){
    boolean matches = false;
    return matches;
    }Ok, the getting the double from the money string one
    is easy, just search through the string until you
    find some numbers, and strip out any commas.
    If anyone has any ideas on a clever way of doing the
    date parsing, and the string compare one, or knows of
    existing methods to do these, I'd love to hear about
    it.
    Many long hours of messing around with string
    operations await me otherwise!
    Thanks

  • String parsing

    Hi guys,
    Suppose, I have the following line that is read from a file:
    "test" "aksks" 1 "ru"
    How can I parse the above line into the following format:
    String tmp = "test";
    String tmp1 = "aksks";
    Int id = 1;
    String tmp3 = "ru";
    Each word is separated by a single space.
    Thank you!
    Leon

    Use StringTokenizer
    String line = "test aksks 1 ru";
    StringTokenizer st = new StringTokenizer(line, " ");
    String tmp = st.nextToken();
    String tmp1 = st.nextToken();
    int id = Integer.parseInt(st.nextToken());
    String tmp3 = st.nextToken();
    Hope that helped...

  • String parsing for ip addresses

    Hello,
    Could someone suggest a way or give me some example code to parse the following string?:
    I will have a string something like:
    Internet Address Src: 1.2.3.4 and Dst: 5.6.7.8
    I need to parse this string to store the source IP address 1.2.3.4 in a string call sourceIP and the destination IP address 5.6.7.8 in a string called destinationIP.
    Any suggestions appreciated.
    Many thanks.

    Hello,
    Many thanks for the reply. I have taken on board your advice and now have the following code:
      if ((trimmedstring.startsWith("Internet Protocol, Src Addr:"))){
                System.out.println("<br>" + trimmedstring);
                  //indexof, substring
                int firstmarker = trimmedstring.indexOf("Src Addr:");
                System.out.println("MARKER1" + firstmarker);
                firstIPAddress = trimmedstring.substring(firstmarker, trimmedstring.indexOf("("));
                String newFirstIPAddress = firstIPAddress.replaceAll("Src Addr:", "");
                System.out.println("NBNB First IP Address" + newFirstIPAddress);
                int secondmarker = trimmedstring.indexOf("Dst Addr: ");
                System.out.println("MARKER2" + secondmarker);
                secondIPAddress = trimmedstring.substring(secondmarker, trimmedstring.indexOf("("));
                String newSecondIPAddress = secondIPAddress.replaceAll("Dst Addr: ", "");
                System.out.println("<br>NBNB Second IP Address" + newSecondIPAddress);
              }However I am getting an error when I try to parse out the second IP address i.e. the destination IP address.
    I get the error:
    StringIndexOutOfBoundsException: String index out of range: -17
    The line that I'm working on is:
    Internet Protocol, Src Addr: 157.190.70.67 (157.190.70.67), Dst Addr: 157.190.74.153 (157.190.74.153)
    I don't see where my code should be changed as I think the indexes look correct.
    Any ideas?
    Many thanks

  • String parsing (reversing)

    Hello friedns,
    I have string of the form :
    String s1 = "alex box (hello (how (are))) (sachin how are you) d  you"I want to reverse this string as follows :
    String reversed = "you d (sachin how are you) (hello (how (are))) box alex"Note : In the above translation if there is something inside parenthesis then,
    I want to use it as a single word and I will not reverse the content inside it.
    Would somebody can tell me how can I make such type of translation ?
    Thank you.
    regards,
    sachin

    sachin.annadate wrote:
    Hello friedns,
    I have string of the form :
    String s1 = "alex box (hello (how (are))) (sachin how are you) d  you"I want to reverse this string as follows :
    String reversed = "you d (sachin how are you) (hello (how (are))) box alex"Note : In the above translation if there is something inside parenthesis then,
    I want to use it as a single word and I will not reverse the content inside it.
    Would somebody can tell me how can I make such type of translation ?
    Thank you.
    regards,
    sachinThis looks a lot like your previous post:
    [http://forum.java.sun.com/thread.jspa?threadID=5301673]
    I suggested looking at ANTLR. I will do so again: create a grammar of your language and then let ANTLR do the "dirty" work by generating a lexer and parser for you.

Maybe you are looking for

  • IPod Classic no longer syncs all video podcasts

    My iPod Classic 30 GB used to play Onion News Network and TED videos, no problem. Now I get a message when I try to sync them that says 'Cannot be played on your iPod.' These are TED videos dating back to 2009, and similarly old Onion News Network vi

  • LiveCycle Newbie: Validate Before Printing Form

    I have a form created in Adobe Acrobat Pro that I have brought into LiveCycle to add print and emails buttons to. However, I need a specific functionality added to the standard "Print" button. It is a legal form that has required fields and the clien

  • Coherence exception in JPA

    Hi, I am using open jpa for persistence in my clustered weblogic server envirnment. I am using coherence for locking support and distributed cache mgmt. But while creating entity manager from the Persistence.xml file, i am getting an error, for which

  • Reconciliation between two R/3 tables

    Hi, this might be the wrong board for this, sorry! Does anyone know a report with which you can compare the GL totals table (GLT0) with the line item tables (BSEG BKPF)? We have loaded line items and totals into two different cubes and the data doesn

  • Lost serial number - Vibe X2

    Hello, I need to restore my NVRAM after a failed OTA update. I cannot seem to find the serial number of my phone anywhere, it is a Vibe X2-CU. The box only has my IMEI numbers on and some Tenna info. Does anybody have an idea of how I can get my seri