You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by JR...@penntraffic.com on 2007/05/18 00:43:24 UTC
Error parsing XML with DOMParser
I'm receiving an XML document over a TCP socket, I then instantiate an
instance of DOMParser and attempt to parse the data. I get the identical
exception when using Xerces-J as well. Here's the exception:
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x0) was
found in markup after the end of the element content.
at
org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213)
at
org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XMLDocumentScanner.java:588)
at
org.apache.xerces.framework.XMLDocumentScanner$TrailingMiscDispatcher.dispatch(XMLDocumentScanner.java:1461)
at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at
org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
Here's the relevant snippet(s) of source (there is code to write out the
socket, just not here):
Socket socket = new Socket( hostIP, hostPort );
OutputStream outStream = socket.getOutputStream();
InputStream inStream = socket.getInputStream();
DataInputStream dataInStream = new DataInputStream( inStream );
byte[] inByteArray = new byte[ 2048 ];
int length = dataInStream.read( inByteArray );
InputStream byteData = new ByteArrayInputStream( inByteArray );
try
{
DOMParser dp = new DOMParser();
dp.parse( new InputSource( byteData ));
Document doc = dp.getDocument();
}
catch ( Exception e )
{
e.printStackTrace();
System.exit( 1 );
}
Is there a different way to do this? I even tried creating a new String
based on the length read from the socket, minus one. The parser then saw
that the final angle bracket of my root element was missing, so it doesn't
seem to be an encoding issue.
Any help would be appreciated.
Jeff
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Error parsing XML with DOMParser
Posted by JR...@penntraffic.com.
I did write both the client and the server. Thanks for the link. There's
no problem with the protocol, I'm just having issues with the conversion
of the data to the various format (classes) for the DOMParser methods.
Jeff
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Error parsing XML with DOMParser
Posted by JR...@penntraffic.com.
Very elegant solution. My client (Java) application communicates with C
server application, compiled with MetaWare's HighC compiler, but the ideas
are very reusable. Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Error parsing XML with DOMParser
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Jeff,
There's a sample [1] included with Xerces which shows how you can process
XML documents (multiple ones or a single one followed by arbitrary data)
sent over a socket. If you're in control of both ends of the stream, you
might want to implement something like that.
Thanks.
[1]
http://svn.apache.org/viewvc/xerces/java/trunk/samples/socket/KeepSocketOpen.java?revision=447688&view=markup
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
<JR...@penntraffic.com> wrote on 05/17/2007 06:43:24 PM:
> I'm receiving an XML document over a TCP socket, I then instantiate an
> instance of DOMParser and attempt to parse the data. I get the
identical
> exception when using Xerces-J as well. Here's the exception:
>
> org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x0)
was
> found in markup after the end of the element content.
> at
> org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213)
> at
> org.apache.xerces.framework.XMLDocumentScanner.
> reportFatalXMLError(XMLDocumentScanner.java:588)
> at
> org.apache.xerces.framework.
> XMLDocumentScanner$TrailingMiscDispatcher.
> dispatch(XMLDocumentScanner.java:1461)
> at
> org.apache.xerces.framework.XMLDocumentScanner.
> parseSome(XMLDocumentScanner.java:381)
> at
> org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
>
> Here's the relevant snippet(s) of source (there is code to write out the
> socket, just not here):
>
> Socket socket = new Socket( hostIP, hostPort );
> OutputStream outStream = socket.getOutputStream();
> InputStream inStream = socket.getInputStream();
> DataInputStream dataInStream = new DataInputStream( inStream );
> byte[] inByteArray = new byte[ 2048 ];
> int length = dataInStream.read( inByteArray );
> InputStream byteData = new ByteArrayInputStream( inByteArray );
>
> try
> {
> DOMParser dp = new DOMParser();
> dp.parse( new InputSource( byteData ));
> Document doc = dp.getDocument();
> }
> catch ( Exception e )
> {
> e.printStackTrace();
> System.exit( 1 );
> }
>
> Is there a different way to do this? I even tried creating a new String
> based on the length read from the socket, minus one. The parser then
saw
> that the final angle bracket of my root element was missing, so it
doesn't
> seem to be an encoding issue.
>
> Any help would be appreciated.
> Jeff
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org