Problem with sax parser

Hello..
I have the following problem. When I parse an xml document with blank spaces and numbers with decimals, its sometimes comes out as one string and sometimes as two, for example "First A" sometimes comes out as "First" and "A" and sometimes as "First A", which is how its stored in the xml file. Same with numbers like 19.20. Im enclosing a little of my code..
public void characters(char buf[], int offset, int len)
throws SAXException
if (textBuffer != null) {
SaveString = ""+textBuffer;
if(i>-1)
numbers = SaveString;
Whats wrong and how do I fix it.
Best Regards Dan
PS I have more code, in data and out data if needed.Ds

Hello,
I do not know if this is your problem, yet please find hereafter an excerpt of the SAX API:
public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
... SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks;...
... Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so)...
In other words, I am afraid that your issue is the "standard behaviour" of a SAX parser.
I hope it helps.

Similar Messages

  • Problem with SAX parser - entity must finish with a semi-colon

    Hi,
    I'm pretty new to the complexities of using SAXParserFactory and its cousins of XMLReaderAdapter, HTMLBuilder, HTMLDocument, entity resolvers and the like, so wondered if perhaps someone could give me a hand with this problem.
    In a nutshell, my code is really nothing more than a glorified HTML parser - a web page editor, if you like. I read in an HTML file (only one that my software has created in the first place), parse it, then produce a Swing representation of the various tags I've parsed from the page and display this on a canvas. So, for instance, I would convert a simple <TABLE> of three rows and one column, via an HTMLTableElement, into a Swing JPanel containing three JLabels, suitably laid out.
    I then allow the user to amend the values of the various HTML attributes, and I then write the HTML representation back to the web page.
    It works reasonably well, albeit a bit heavy on resources. Here's a summary of the code for parsing an HTML file:
          htmlBuilder = new HTMLBuilder();
    parserFactory = SAXParserFactory.newInstance();
    parserFactory.setValidating(false);
    parserFactory.setNamespaceAware(true);
    FileInputStream fileInputStream = new FileInputStream(htmlFile);
    InputSource inputSource = new InputSource(fileInputStream);
    DoctypeChangerStream changer = new DoctypeChangerStream(inputSource.getByteStream());
    changer.setGenerator(
       new DoctypeGenerator()
          public Doctype generate(Doctype old)
             return new DoctypeImpl
             old.getRootElement(),
                              old.getPublicId(),
                              old.getSystemId(),
             old.getInternalSubset()
          resolver = new TSLLocalEntityResolver("-//W3C//DTD XHTML 1.0 Transitional//EN", "xhtml1-transitional.dtd");
          readerAdapter = new XMLReaderAdapter(parserFactory.newSAXParser().getXMLReader());
          readerAdapter.setDocumentHandler(htmlBuilder);
          readerAdapter.setEntityResolver(resolver);
          readerAdapter.parse(inputSource);
          htmlDocument = htmlBuilder.getHTMLDocument();
          htmlBody = (HTMLBodyElement)htmlDocument.getBody();
          traversal = (DocumentTraversal)htmlDocument;
          walker = traversal.createTreeWalker(htmlBody,NodeFilter.SHOW_ELEMENT, null, true);
          rootNode = new DefaultMutableTreeNode(new WidgetTreeRootNode(htmlFile));
          createNodes(walker); However, I'm having a problem parsing a piece of HTML for a streaming video widget. The key part of this HTML is as follows:
                <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
                  id="client"
            width="100%"
            height="100%"
                  codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
                  <param name="movie" value="client.swf?user=lkcl&stream=stream2&streamtype=live&server=rtmp://192.168.250.206/oflaDemo" />
             etc....You will see that the <param> tag in the HTML has a value attribute which is a URL plus three URL parameters - looks absolutely standard, and in fact works absolutely correctly in a browser. However, when my readerAdapter.parse() method gets to this point, it throws an exception saying that there should be a semi-colon after the entity 'stream'. I can see whats happening - basically the SAXParser thinks that the ampersand marks the start of a new entity. When it finds '&stream' it expects it to finish with a semi-colon (e.g. much like and other such HTML characters). The only way I can get the parser past this point is to encode all the relevant ampersands to %26 -- but then the web page stops working ! Aaargh....
    Can someone explain what my options are for getting around this problem ? Some property I can set on the parser ? A different DTD ? Not to use SAX at all ? Override the parser's exception handler ? A completely different approach ?!
    Could you provide a simple example to explain what you mean ?
    Thanks in anticipation !

    You probably don't have the ampersands in your "value" attribute escaped properly. It should look like this:
    value="client.swf?user=lkcl&stream=...{code}
    Most HTML processors (i.e. browsers) will overlook that omission, because almost nobody does it right when they are generating HTML by hand, but XML processors won't.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Problem with SAX parser with String format

    hi, all I have the next problem:
    I try to parse xml file with success, I write next code:
    ====================
    my_class saxUms = new my_class();
    File file = new File( "c:\\my_try_Response.xml" );
    InputSource src1 = new InputSource( new FileInputStream( file ) );
    XMLReader rdr = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" );          rdr.setContentHandler( saxUms );
    rdr.parse(src1);
    ===================
    but when I try to parse the same in string variable, I write:
    ===================
    my_class saxUms = new my_class();
    StringReader strr = new StringReader(my_str);
    InputSource intt = new InputSource(strr);
    XMLReader prs= XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" );
    prs.setContentHandler(saxUms);
    prs.parse(intt);
    ===================
    and error occurs:
              "Exception: java.lang.ClassCastException: java.lang.StringBuffer"
    how to fix the problem?
    Thank you for collaboration!

    where does the exception stack trace say the error is occurring?

  • Problem with SimpleDateFormat.parse()

    Hello
    I have a problem with the parse-function in SimpleDateFormat.
    When i try to parse the date Fri Jul 15 17:23:41 2005 with this pattern EEE MMM d HH:mm:ss yyyy i get the exception java.text.ParseException: Unparseable date: "Fri Jul 15 17:23:41 2005".
    This is my code:
    SimpleDateFormat df=new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy");
    try {
      df.parse(strDate);
    } catch (ParseException e) {
      e.printStackTrace();
    }Can someone explain me what i did wrong?
    Thanks
    Matthias

    Since your name is "Matthias" it is possible that your locale is one that does not use the English language. If that is the case then your problem is that "Fri" or "Jul" are not correct abbreviations in your language.
    Easiest way to test this idea is to format a date (such as now) using that SimpleDateFormat object and see what the output looks like.

  • Problem Using Sax parser with Eclipse 3.0 and command line

    Hi,
    I am parsing a xml file with sax. When I am running my programm in the command line everthing is ok and I get the right results from parsing.
    But if I am running the programm in Eclipse 3.0 (the same java code) I get an other result (the wrong results).
    Does anybody know what this can be the reason for. Is Eclipse using an other xml parser and if where I can change the parser?
    It would be very kind if somebody can give me a reason for this strange behaviour.
    Thanks in advance

    I have solved my problem.
    In the command line I used jre 1.4 and in Eclipse I used jre 1.5.
    I think jre 1.5 uses an other xml parser so I got an other result.
    If i use in Eclipse jre1.4 I get the same result as in the command line.

  • Problem with XML Parser For Java V2

    Get message:
    <Line 5, Column 40>: XSD-2021: (Error) Element not completed: 'doesNotWork'
    Parser Exception: Element not completed: 'doesNotWork'
    Element 'doesNotWork' is defined the same as 'works' except 'doesNotWork' uses a ref="" rather than defining element inline.
    This appears to be a bug in the parser.
    XML:
    <?xml version ="1.0"?>
    <example>
    <works anAttribute="something"/>
    <doesNotWork anAttribute="something"/>
    </example>
    Schema:
    <?xml version = "1.0" encoding = "UTF-8"?>
    <xsd:schema xmlns:xsd = "http://www.w3.org/2000/10/XMLSchema">
    <xsd:element name = "example">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="works">
    <xsd:complexType>
    <xsd:attribute name = "anAttribute" use = "required" type = "xsd:string"/>
    </xsd:complexType>
    </xsd:element>
    <xsd:element ref = "doesNotWork"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name = "doesNotWork">
    <xsd:complexType>
    <xsd:attribute name = "anAttribute" use = "required" type = "xsd:string"/>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>

    Hi all,
    I am getting the same error. Is the schema parser being actively suppported. From replies to problems, it does not seem like it is. Also I am still having problems with 'required', ID attributes etc. Is there comprehensive documentation of what is and what is not supported.
    Any help appreciated
    Thanks
    Venu

  • Problem with SAX characters method

    Well I already used SAX on couple occasions, and there was no problems. But this time I have weird situation. characters method from handler class (SAX parser) does not handle XML element at once, but in two passes. For example:
    <some>this is some text</some>is handled by calling characters method TWICE (e.g. 'this is' and 'some text'). Is this normal behavior, or I do not form XML file properly? If it is normal, can anyone tell me how to detect this behavior?
    Every help is appreciated. Cheers!
    Message was edited by:
    zly

    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPSAX3.html
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4316794
    http://forum.java.sun.com/thread.jspa?threadID=5130656&tstart=0

  • Problem with C++ parser V2

    Hi,
    I encountered some problems with C++ XML Parser on NT (0acle 8.1.7).
    I can't use the function print on a Node
    => error LNK2001: unresolved external symbol "public: void __thiscall Node::print(unsigned char *,unsigned int,unsigned int,unsigned int)" (?print@Node@@QAEXPAEIII@Z)
    is this function exported ??
    I have not this problhme on Unix !
    (to work around on NT, i use the printBuffer function)
    Thanks,
    null

    Do you know when this future release will be available for NT, AIX and Compaq ?
    null

  • Problem with registering Parser - Recompiled source code, don't see any changes

    I had created a parser. I had register this parser with Ifs Manager. I had execute this following statement to see if been registered carefully:
    On user ifssys/ifssys
    sql)select name,stringvalue,bundle from odmv_property where name= 'p01';
    I see my parser....
    select name from odmv_propertybundle where id=1139;
    ParserLookupByFileExtension
    All it's ok. I upload a file with a 'p01' extension with option 'parser' on my Internet Explorer. All work fine.. My parser work. But I need to do some changes in my code. I update my code, recompile my code. My class file have been updated. After my parser (.class) file have been updated I upload a new file with parse option. I don't see any change I do in my code. Why??? How I can update my parser to view change. I have only recompile my code an place my new class files on the same directory. I have try again (change on code, recompile, test) and I don't see any changes.
    But I have test by change my classname. My classname before is Test1 and I have rename my classe by Test2. I have compiled this code and a file Test2.class have been generate. I have update my register parser with Ifs Manager to use the new classname Test2. I have chack with sql statement to see if my parser have been updated. I have been updated correctly. I have upload a new file with parse option and I see my change on my code..
    Do you have some explanations about that??
    How I can update my source code of a parser already registered to the parser take the change I do.
    Francois
    null

    Ok, but they have another manner to resolve this problem. If I upload a file with parser option on Windows Nt explorer (Using SmbServer or WcpServer). How I can update the class file into the JVM? I need the restart this those server or just one? If just one which server I need to restart?
    Thanks Francois
    null

  • Probem with SAX parser

    Hi to averybody!
    I'm trying to parse a xml file using SAX parser but I found a problem.
    When the method
    public void characters(char[] ch, int start, int length)
    I try to print the content in this way:
    for (int i = start; i <= length; i++)
    System.out.print(ch);
    but nothing is printed except except in 2 cases.
    the file parsed start like this:
    <BatchMaint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ncr.com/bosphoenix/WSMaintenance_5.0.xsd">
    <Id>1000950</Id>
    <DateTime>2009-02-11T11:37:09</DateTime>
    <FromPC>TD185008-1J7</FromPC>
    <FromAppl>BatchToPosWS.dll</FromAppl>
    <FromVersion>001.000.000.000</FromVersion>
    the method print only "1000950" and "2009-02-11T11:37:09".
    Has somebody any idea how fix the problem??

    From the API documentation for the characters() method:
    "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."

  • How to Create XML file with SAX parser instead of DOM parser

    HI ALL,
    I am in need of creating an XML file by SAX parser ONLY. As far as my knowledge goes, we can use DOM for such purpose(by using createElement, creatAttribute ...). Can anyone tell me, is there any way to create an XML file using SAX Parser only. I mean, I just want to know whether SAX provides any sort of api for Creatign an element, attribute etc. I know that SAX is for event based parsing. But my requirement is to create an XML file from using only SAX parser.
    Any help would be appreciated
    Thanx in advance
    Kaushik

    Hi,
    You must write a XMLWriter class yourself, and that Class extends DefaultHandle ....., the overwrite the startElement(url, localName, qName, attributeList), startDocument(), endElement().....and so on.
    in startElement write your own logic about how to create a new element and how to create a Attribute list
    in startDocument write your own logic about how to build a document and encodeType, dtd....
    By using:
    XMLWriter out = new XMLWriter()
    out.startDocument();
    Attribute attr1 = new Atribute();
    attr1.add("name", "value");
    out.startElement("","","Element1", attr1);
    Attribute attr2 = new Atribute();
    attr2.add("name", "value");
    out.startElement("","","Element2", attr2);
    out.endElement("","","Element2");
    out.endElement("","","Element1");
    out.endDocument();

  • Problem with C++ parser V2 (XDK 9.0.1.2.0)

    Hi,
    The problem describe in a previous message (id=416237, march 2001) with the C++ XDK 8.1.7.1 still remains with the new XDK!
    I can't use the function print to a FILE* on a Node.
    I try to print to stdout or a file =>
    [Linstruction ` + 0x77F7CE4C ; emploie ladresse mimoire + 0x000000010 ;. La mimoire ne peut pas jtre + written ;.]
    No problem when I print to a buffer.
    To try it, i modified DOMSample.cpp :
    cout << "Dump the DOM" << endl;
    cout.flush();
    oratext xmlBuff[1024];
    //parser.getDocumentElement()->print(xmlBuff,1024,0,0); // it's ok
    parser.getDocumentElement()->print(); // don't work
    Thanks,

    This is a known issue and is being investigated. It only fails on Windows NT and the access violation occurs in the Windows NT stdio functions.

  • SSXA: Problems with QueryText Parsing

    Hi.
    I have a strange issue with Site Studio For Extenal Application WebSite.
    I have a Element Definition that have a Query. Editing Data File and using this query directly in UCM works fine. However when i edit this Data File from wcm-contrib (directly in web) i'm getting a Query Text Parse error.
    From log file:
    services/6 05.21 15:43:38.176 IdcServer-6452035 !csSearchQueryParserParsingError,( xFCCContentTypes &lt;matches&gt; `5` &lt;AND&gt; xFCCContentTypesN2 &lt;matches&gt; `8` &lt;AND&gt; xWebsiteObjectType &lt;matches&gt; `Image` ),19 exception stack
    It's a encoding problem?. How can i solve it?.
    Thanks in advance.
    Regards.

    Hi,
    What is the full build version of UCM being used ?
    Thanks
    Srinath

  • Strange problem with SimpleDateFormat.parse method

    I got something strange with this method.
    String pattern = "yyyy/MM/dd";
    String mydate = "2007/00/10";
    SimpleDateFormat formatter = new SimpleDateFormat(pattern);
    Date newdate = formatter.parse(mydate);
    I get "2006/12/10"
    is this correct.

    dongyisu wrote:
    and there no exception get thrown outYes it does. I ran this:
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class DateFormatTest
       public static final String DEFAULT_DATE_FORMAT = "yyyy/MM/dd";
       public static void main(String[] args)
          DateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
          formatter.setLenient(false);
          for (int i = 0; i < args.length; ++i)
             try
                Date date = formatter.parse(args);
    System.out.println("input: " + args[i] + " date: " + date);
    catch (ParseException e)
    System.err.println(args[i] + " is not a valid date");
    and got this when I input "2007/00/10":
    com.intellij.rt.execution.application.AppMain DateFormatTest 2007/00/10
    2007/00/10 is not a valid date
    Process finished with exit code 0%

  • Problem on sax parser

    why this does not work
    import java.io.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    import javax.xml.parsers.SAXParserFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    public class XMLParser extends DefaultHandler
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser myparser = factory.newSAXParser();
    myparser.parse(new File("c:/first.xml"), handler);

    Put your code inside a method!

Maybe you are looking for

  • Error in Saving Domain in CMS

    Hi Experts, When i trying to save the domain information in CMS , i am getting the following error. Unexpected error; inform your system administrator: <Localization failed: ResourceBundle='com.sap.cms.util.exception.CMSExceptionMessages', ID='SLD na

  • ABAP Objects, OLE & Cool:Gen

    Hello ABAP-ers, I have been messing around for a few hours now trying to get the right statements, but gettings desparate or better said angry, so Im posting this message in the hope to get some useful tips. For a customer I am developing an ABAP cla

  • Getting a specific number of rows

    Hi, I would like to know how to get a specific number of rows. For example, I want to page data in my web application, so I'd like to be able to retrieve just 25 rows in my SELECT statement. I searched and I couldn't see anything under the obvious ke

  • Re: Workflow for Document

    Hi All, PLease advise me how to configure a workflow for a document. I would appreciate if I would be explained step by step. My requirement is that I create a document. It should go in workflow for approval before it can be released and put is use.

  • Unable to add Gatekeeper

    Hi to all, I'm new in Cisco Voice Portal. I have installed CVP, then checked all services are running. After that I have added CallServer, Reporting, VXML servers, etc. But I cannot add Gatekeeper from Device Managenemt menu. I can't understand diffe