Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

streaming/incremental XML parsing

Status
Not open for further replies.

riches85

Programmer
Nov 13, 2002
59
US
Has anyone had the experience of parsing streaming XML? I need to be able to parse XML over a socket connection in Java and most parsers expect a whold document at once. Im curious if anyone has found a way to do it and can steer me in the right direction. Thanks in advance.
 
You want a SAX style parser. I'm not a Java guy, but what they do is, after you point them to a file (or stream, depending on the implementation's capabilities), it raises events as it sees elements, attributes, etc.

You then say, in each event (for example, the element events) "Is this an element I'm interested in?". If not, you just let it go on by. If it is, you do some work with it.

Frequently you need to wait until the end-element tag, and then perform some work on a complete record. What you do then is when you see the start-element tag, you start building a string. As you see each element, attribute, and element text go by, you add them to your string. When you get to the end of the element, you have a complete record in string format, to which you can load it into a DOM, write it to a file, whatever you want.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
please do not crosspost with other forums here (Java forum)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top