Just my 2 cents. I'm solving the same problem for a Jabber API that I'm writing for a distributed project that I'm apart of. I'm using JDK 1.4.1 so I take advantage of the regex library to tokenize the stream and NIO to prevent blocking caused by the parser trying to buffer the XML content. I've had to customized a couple of the regular I/O classes to reduce the number of transient objects (garbage) required to go from channels (nio) to streams. If you are interested we can talk off list.
Dane Foster Equity Technology Group, Inc. http://www.equitytg.com 954.360.9800 ----- Original Message ----- From: "James Strachan" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Thursday, September 05, 2002 14:09 Subject: Re: [dom4j-user] TCP/IP stream to XML document ? When reading XML over a socket, generically, you need to use a protocol which denotes when the XML stops. Looking for the last > doesn't work since comments, whitespace and processing instructions can occur outside of the root element. So if you were to send multiple documents on the same socket, the end of one document could invalidate the begiinning of the next document (since the XML declaration must be the first line) So try using, say, HTTP or MIME encoding or writing the length of the XML file first then you know how many bytes to read etc. This has been discussed in this thread... http://www.mail-archive.com/dom4j-dev%40lists.sourceforge.net/msg00400.html Details of how to disable DTD validation, or at least to fetch DTDs from local files or inside jars on the classpath are here... http://www.mail-archive.com/dom4j-user@lists.sourceforge.net/msg01005.html James ------- http://radio.weblogs.com/0112098/ ----- Original Message ----- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, September 05, 2002 2:16 PM Subject: [dom4j-user] TCP/IP stream to XML document ? 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); } } } ------------------------------------------------------------------------------ Changed your e-mail? Keep your contacts! Use this free e-mail change of address service from Return Path. Register now! ------------------------------------------------------- This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE! https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user