Hi there,
I would like to read XML
messages from a TCP/IP stream. One issue
is determining the end of an
XML message. My latest solution just
tries to parse the message
everytime it receives a ">".
Now the Problem: the parsing
always automatically tries to retrieve
the DTD and do a validation.
But if the DTD does not exist, every
parsing attempt takes
forever.
Question: How can I
completely disable DTD retrieval and validation ?
Any sugegstion how I should
modify my sample code below ?
thanx Mike
-------------------- cut
here --------------------
import java.io.*;
import
java.net.*;
import java.util.*;
import org.dom4j.*;
import
org.dom4j.io.*;
import org.apache.log4j.*;
/**
* Read XML from TCP/IP connection and create a
document.
*/
public class TCP2XML {
static Category log =
Category.getInstance(TCP2XML.class.getName());
public static void
main(String[] args) {
BasicConfigurator.configure();
int port = 9999;
try
{
// open server
socket
ServerSocket myServerSocket = new
ServerSocket(port);
boolean loop =
true;
while (loop) {
log.debug("run() - waiting for a new socket
connection");
// wait for an incoming
connection
Socket sock = myServerSocket.accept();
log.info("run()
- new connection from " + sock.getInetAddress());
InputStream input =
sock.getInputStream();
StringBuffer str = new
StringBuffer();
int i;
// read every character from
input stream
while ((i = input.read()) >= 0)
{
str.append((char)i);
if ('>' == (char)i) {
try
{
Document doc =
DocumentHelper.parseText(str.toString());
// if I get here, I have a
complete document
log.info("COMPLETE:" +
str);
} catch (DocumentException de) {
log.info("INCOMPLETE:" +
str, de);
}
}
}
}
}
catch
(IOException ioe) {
log.warn("IOEException", ioe);
}
}
}