I
realized my problem right after I sent my email, so I already changed it to use
HTTP. I already have some HTTP Stream classes I'm using elsewhere - so
it's working now.
Thanks!
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Brian Young
Sent: Tuesday, March 26, 2002 4:00 PM
To: David Hooker
Cc: [EMAIL PROTECTED]
Subject: Re: [dom4j-user] Help reading xml from socket
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Brian Young
Sent: Tuesday, March 26, 2002 4:00 PM
To: David Hooker
Cc: [EMAIL PROTECTED]
Subject: Re: [dom4j-user] Help reading xml from socket
David,
This is a common problem people encounter when working with sockets and probably not a dom4j issue. The socket essentially stays open and there will not be a way to determine when the client is done sending data unless you investigate the data itself. Flush() was a good try but it will not solve this problem. I doubt that dom4j is doing a lot of intelligence to find out when the whole document has been collected (i.e. looking for the end of the root tag, etc) You may want to consider implementing the HTTP protocol and sending the data off after you collect it. HTTP has a content-length header variable so you know when to stop reading. Or, you could look for the start and end tags occuring in the data yourself and then send the collected data on to dom4j.
Outside of your problem, for what it is worth- piping data right from a socket into dom4j is probably not the best design- I'd focus on collecting the data first like I mentioned above and then continuing. This will give you an adequate abstraction layer for better error handling and so forth. The current design is too tied to the network layer for my preference.
Good luck!
Brian
David Hooker wrote:
000801c1d50c$e495c930$6901a8c0@DHOOKER" type="cite">I have a socket from which I'm receiving xml. I need to create a Document object from this. Once the xml comes in, I need to leave the socket open for other data to come in. Here's the receiving code:private Document getDocumentFromStream(InputStream xmlStream)
{
Document doc = null;SAXReader reader = new SAXReader();
reader.setValidation(false);try
{
doc = reader.read(xmlStream);
}
catch(DocumentException de)
{
System.out.println("error");}
return doc;
}Now, the sender is calling flush() on the stream after it sends the xml, but it isn't closing the socket. Does the SAXReader know when the end of the xml data is so that it can construct and return the Document - without me having to close the stream to signal it that there is no more data?
