Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

"Content is not allowed in trailing section" error in JAXP 1.1

843834Oct 10 2008 — edited Oct 28 2009
Hi All,

I'm trying to write parse XML using JAXP 1.1. I've given input to parser as shown in below code.
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
parser.parse(new File(args[0], handler);
this worked for me. But I've tried to pass java.io.InputStream reference to the overloaded parse() method of SAXParser class, it throwed the following exception
org.xml.sax.SAXParseException: Content is not allowed in trailing section.
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:143)
at CMMCompareHelper.main(CMMCompareHelper.java:234)
I'm using JAXP 1.1 with J2SE 1..4.2. My requirement is that I get the XML as a String and I've tried to convert it to java.io.ByteArrayInputStream and passed to the SAXParser. It din't work. Code I've written to do this is shown below:
FileInputStream in = new FileInputStream(new File(args[0]));
			
byte[] buf = new byte[512];
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
while(in.read(buf) != -1){
    byteOut.write(buf);				
}
InputStream newCMMStream = new ByteArrayInputStream(byteOut.toByteArray());			
SAXParser parser = factory.newSAXParser();			
parser.parse(newCMMStream, handler);		
Am I doing something wrong?
Thanks in advance for any help in this regard.

Satya
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 25 2009
Added on Oct 10 2008
9 comments
6,993 views