wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes SAX Parsing a one-line XML document Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "SAX Parsing a one-line XML document" Watch "SAX Parsing a one-line XML document" New topic
Author

SAX Parsing a one-line XML document

Peter Kleczka
Greenhorn

Joined: Feb 09, 2003
Posts: 18
Hi

I'm trying to parse a file that has no carriage returns
between the XML tags. In other words, the XML document is
all on one line. The parser doesn't seem to pick up
any of the content inside these tags unless I separate
the tags with hard returns.

Here is some of my code....


Is there something special I should be doing in the parser or
content handler? The XML string I'll be getting is comming from
another website, so I don't really have control of the XML document.

TIA
Pete (pkleczka@yahoo.com)
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Peter Kleczka:
I'm trying to parse a file that has no carriage returns
between the XML tags. In other words, the XML document is
all on one line. The parser doesn't seem to pick up
any of the content inside these tags unless I separate
the tags with hard returns.

This sounds to me like there's something wrong with the parser implementation. Which parser are you using?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Peter Kleczka
Greenhorn

Joined: Feb 09, 2003
Posts: 18
I'm using Xerces but I'm not sure which version I'm using.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
So is the problem that your characters(char[], int, int) method doesn't get called unless you add a '\n' between each <element>?
Peter Kleczka
Greenhorn

Joined: Feb 09, 2003
Posts: 18
Sorry the real problem was an SAPIU (Stupid API User) error

I was overcomplicating the callback methods in the ContentHandler
and that made it appear that the parser was not doing things properly.
All I need to do is keep track of the current tag, and if it is not
an end tag print its contents. So my new code looks like the following...



Thanks,
Pete
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SAX Parsing a one-line XML document