[jdom-interest] Request for help: building a document from an InputStream
Matthew MacKenzie
matt at xmlglobal.com
Thu Aug 16 09:38:07 PDT 2001
You might build a little bit of a protocol, so the message looked
something like:
LEN 29
<?xml version="1.0"?>
<mydoc />
LEN == Byte length, this way you could read LEN bytes then build the
document - OR implement your own builder that encapsulated that.
Just an idea. If you are doing raw sockets, you need to have a little
bit of a protocol, otherwise just use HTTP.
-Matt
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