You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by JR...@penntraffic.com on 2007/05/18 00:40:30 UTC

Error parsing XML document 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.  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 (I didn't include the code which 
writes out the socket, but it does):

[code]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 );
}[/code]

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: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Re: Error parsing XML document with DOMParser

Posted by David Crossley <cr...@apache.org>.
You have posted to the general XML list. You would do better
by using the Apache Xerces J users mailing list:
http://xerces.apache.org/ .. i cannot find the mailing list
subscription info for you. Try the usual xerces-j-users-subscribe
at xerces.apache.org

-David

JRancier wrote:
> I'm receiving an XML document over a TCP socket, I then instantiate an 
> instance of DOMParser and attempt to parse the data.  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 (I didn't include the code which 
> writes out the socket, but it does):
> 
> [code]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 );
> }[/code]
> 
> 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: general-unsubscribe@xml.apache.org
> For additional commands, e-mail: general-help@xml.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org