3 Replies Latest reply: Jul 19, 2011 2:23 AM by EJP RSS

    Java SAX XML parser suppresses the specific element value (number datatype)

    827453
      Dear experts,

      We are using SAX XML parser Handler (org.xml.sax.XMLReader) for read the xml file.

      But some times it suppresses the specific element value (number datatype 10 digit column) as below (not all the times).


      Actaul Value     --> Supress value while parsing
      -------------------- ------------------------------------
      1234567890     -->           67890 (last 5 giti)

      1234567890 -->           0

      We have tried to find the problem, where it is exactly occurred. But we couldn’t.

      Please send your comments for this? It’s very urgent and important.


      Details: Server – AIX
      JDK – 1.4
      Jar name -- dom4j-full.jar



      Thanks & Regards
      Muthu

      Edited by: Muthu on Jul 19, 2011 10:54 AM
        • 1. Re: Java SAX XML parser suppresses the specific element value (number datatype)
          EJP
          Do you mean via a ContentHandler.characters() method? You're aware that 'SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks'? You have programmed defensively against that?
          • 2. Re: Java SAX XML parser suppresses the specific element value (number datatype)
            827453
            Yes EJP. You are correct. We have extracted the xml element values using ContentHandler.characters() via only.

            My characters method looks like as below...


            public void characters(char[] ch, int start, int length) throws SAXException
            {
            text = new String(ch, start, length);          
            }

            Actually my xml is

            <details>
                 <acct>
                 <number>1234567890</number>
                 <name>xxx1</name>
                 </acct>
                 <acct>
                 <number>1222567890</number>
                 <name>xxx2</name>
                 </acct>
                 <acct>
                 <number>1233567890</number>
                 <name>xxx3</name>
                 </acct>
            </details>

            Here Acct-->number column is the problem.

            Once i get the acct-->number using characters method, it would be set into the account bean.

            Also i am not aware of that 'SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks'?

            Could you please give your idea regarding how to solve this?

            Regards
            Muthu
            • 3. Re: Java SAX XML parser suppresses the specific element value (number datatype)
              EJP
              Also i am not aware of that 'SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks'?
              That's surprising. It's right there in the Javadoc where I found it.
              Could you please give your idea regarding how to solve this?
              When you get a startElement(), push the name onto a name stack, push the attributes onto an attributes stack if you need them, and push a new StringBuffer onto a StringBuffer stack. When you get characters(), append them to the StringBuffer at the top of the stack. When you get an endElement(), pop the name off the name stack, pop the StringBuffer off its stack, convert to a String, then the value of the element with that name is that string. If you need the attributes pop them off their stack too.