Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SAX Parsing a one-line XML document

 
Peter Kleczka
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Peter Kleczka
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Xerces but I'm not sure which version I'm using.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic