jQuery in Action, 3rd edition
The moose likes XML and Related Technologies and the fly likes Parsing with DOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing with DOM "hangs": inputstream problem" Watch "Parsing with DOM "hangs": inputstream problem" New topic

Parsing with DOM "hangs": inputstream problem

J.H.B. Oosterlaar
Ranch Hand

Joined: Sep 12, 2002
Posts: 41
We are developing a simple server that translates a XML query to a SQL query, sends that SQL query to the database, translates the result to a XML resultset and sends it back to the connecting client.
We are using DOM to interpret the XML in order to build the XML query, since DOM builds a tree (that we use as a buffer), instead of SAX that has to be interpreted realtime.
Our problem is as follows: the inputstream of the socket act as the input stream for DOM. No exception occures, but at the point when we call domParser.parse();, the thread hangs. When we close the connection, the local output (at the server) is done; the thread continues.
We assume that the following causes the problem: the inputstream is used to read the XML from. But when the XML is sent over the stream, the stream is not closed. Somehow the parser still expects something. When the clientconnection is closed, the stream is closed and the thread can continue; the parser know that the input is ended.
Do you know how to solve this? We cannot just close the connection, because we need to receive the result. Does the parser expects some end indicator? For the inputstream for the parser we use a BufferedReader (otherwise we are getting a NullPointerException).
Thanks! And cheers,
Jeroen Oosterlaar
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Sounds to me like you are not doing a flush() on the output stream that sends the query. That can cause very odd results. Also a final crlf after the closing element might be a good idea.
I agree. Here's the link: http://aspose.com/file-tools
subject: Parsing with DOM "hangs": inputstream problem
It's not a secret anymore!