xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: "David Ondzes" <dondzes AT gmail.com>
- To: xom-interest AT lists.ibiblio.org
- Subject: Re: [XOM-interest] Just gettting started
- Date: Sat, 18 Feb 2006 16:23:52 -0500
On 2/18/06, adamc AT email.unc.edu <adamc AT email.unc.edu> wrote:
> Quoting David Ondzes <dondzes AT gmail.com>:
>
> > Hello All. I am relatively new to XML programming. While looking for
> > an easy to use/getting started XML package I found XOM. I am trying to
> > write an app that reads XML from a socket connection and I am getting
> >
> > "[Fatal Error] :1:1: Content is not allowed in prolog."
>
> That exception message refers specifically to having some text that
> isn't XML markup before the first element. Depending on *how* the text
> you're trying to parse is streamed to you, that well might be the cause
> of the problem you're seeing. For example, if you're getting it "raw"
> over HTTP, the response stream will contain the HTTP headers before the
> XML text.
>
> My suggestion is to try reading the stream first without using
> XOM/Xerces to parse it, and dumping the results to a file or the
> console. This way, you'll be able to see what it is that Xerces (which
> is XOM's default XML parser) is trying to parse.
>
> The first part of your document should be something like what's inside
> the triple quotes below:
>
> """<?xml version="1.0" encoding="utf-8"?>
> <root>
> """
>
> The first line (the XML declaration) is strictly speaking optional, but
> if it's not there the first text in the stream Xerces is trying to
> parse MUST be the root element or a DOCTYPE declaration (which looks
> like """<!DOCTYPE ...""")
>
> Anything else at the beginning of the document and Xerces will
> (rightfully!) complain.
Adam - Thanks for the reply. I was just about to follow up my own post
when I saw your reply. You are right, I had some junk at the beginning
of my stream so I used BufferedInputStream to read the junk and then
sent the stream to the build method.
InputStream is = clientSocket.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
System.err.println("bis.markSupported() = " +
bis.markSupported());
int pos = 0;
while (aByte != '<') {
bis.mark(2);
aByte = (byte) bis.read();
pos++;
}
System.err.println("last byte = " + aByte + " and pos = " +
pos);
bis.reset();
Document doc = parser.build(bis);
I am now seeing the following error I could find a reference to it in
the XOM src or Sax2r3 src.
[Fatal Error] :7879:1: Content is not allowed in trailing section.
Content is not allowed in trailing section. at line 7879, column 1
cause = org.xml.sax.SAXParseException: Content is not allowed in
trailing section.
nu.xom.ParsingException: Content is not allowed in trailing section.
at line 7879, column 1
If my data stream is constant how do I have cut the feed off myself so
the parser can finish ?
I was hoping to write an that would parse the XML feed and constantly
be updating the DOM. I would then periodically take snapshots of the
DOM and pull out the information I was interested in for further
processing.
-
[XOM-interest] Just gettting started,
David Ondzes, 02/18/2006
-
Re: [XOM-interest] Just gettting started,
adamc, 02/18/2006
- Re: [XOM-interest] Just gettting started, David Ondzes, 02/18/2006
-
Re: [XOM-interest] Just gettting started,
adamc, 02/18/2006
Archive powered by MHonArc 2.6.24.