[jdom-interest] Request for help: building a document from an
InputStream
Jason Hunter
jhunter at collab.net
Thu Aug 16 15:39:24 PDT 2001
Sounds like you got whitespace or something coming before <?. By
ignoring the line you take advantage of XML parser's ability to forgive
missing decls.
-jh-
Bob Tykulsker wrote:
>
> Hello World,
>
> I have a java application that is listening on a socket.
> I am sending XML that looks like:
> <?xml version="1.0" encoding="UTF-8"?>
> <message>
> <message_name>request_login</message_name>
> <username>joy</username>
> </message>
>
> I thought I could use code like:
> Buffered Reader sin = new BufferedReader(new
> InputStreamReader(socket.getInputStream()));
> SAXBuilder builder= new SAXBuilder();
> Document doc = builder.build(sin);
> in one fell swoop, but application doesn't seem to get anything until
> interrupt it, at which point it throws the following exception:
> org.jdom.JDOMException: Error on line 8: The XML declaration may only appear
> at the very beginning of the document.
>
> I *CAN* work around this by writing the document without newlines, reading
> the socket a line at a time
> and building the document from a String as per the FAQ:
> while (true) {
> String line = sin.readLine();
>
> if (line.indexOf("xml version") != -1) continuue;
> Document doc = new SAXBuilder().build(new StringReader(line));
> }
>
> Any suggestions?
> Thanks in advance,
>
> Bob
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list