• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about the SAX Parser  RSS feed

 
Fred Victa
Ranch Hand
Posts: 206
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Web service that is using the SAX parser. The SAX parser can split data into multiple chunks. If the data is of type int or double, can that data be split into multiple chunks? I know that if the data is of type String, then it can be split into multiple chunks. Can someone point to some documentation that mentions whether data of type into or double can be split into multiple chunks?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not clear on what your problem is.

XML documents are always text - ie Strings. The SAX parser gives you events for the various components of your XML documents in terms of characters.

It makes no assumption about what int or double is.

IF you have text that represents numbers inside Nodes of type TEXT, the parser may call the characters() method once or multiple times - it is up to the programmer to collect the chunks of characters and decide what they represent when the entire element content has been collected.

It is a common error to take the results of one characters() call and assume you have the entire contents of the element.

Bill
 
Fred Victa
Ranch Hand
Posts: 206
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have the following tag in an XML document:

<PHONE_CALL_REQUIRED code="N"/>

The startXMLElement() method parses this tag to get the attribute. Can the parser call the startXMLElement() method more than once for that tag?
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Victa wrote:The startXMLElement() method parses this tag to get the attribute. Can the parser call the startXMLElement() method more than once for that tag?


The SAX parser doesn't have any such method. However if you meant to ask about the startElement() method... well, I will let the API documentation for the method answer your question:

The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty).
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The startXMLElement() method parses this tag to get the attribute.


No, it is important to keep this straight.

The SAX parser calls the startElement() method AFTER it has parsed the Element tag and all of the attiributes. As far as the parser is concerned, it is DONE at that point - after your custom startElement method returns, the parser continues.

Harold's free online book Processing XML with Java is loaded with examples.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!