[jdom-interest] Request for help: building a document from an InputStream

Bob Tykulsker surftool at pacbell.net
Thu Aug 16 08:41:30 PDT 2001

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"?>

I thought I could use code like:
	Buffered Reader	sin    = new BufferedReader(new
	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,


More information about the jdom-interest mailing list