You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by bu...@apache.org on 2001/09/17 21:09:44 UTC
DO NOT REPLY [Bug 3659] New: -
SAXParser always fails when parsing an xml document
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3659>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3659
Summary: SAXParser always fails when parsing an xml document
Product: Xerces-J
Version: 1.4.3
Platform: PC
OS/Version: Windows NT/2K
Status: NEW
Severity: Critical
Priority: Other
Component: SAX
AssignedTo: xerces-j-dev@xml.apache.org
ReportedBy: jacques.theodas@enron.com
Whenever I try to parse an xml file with the code below, I get a
SAXParseException. The exception is included below as well.
I tried parsing many xml files that were verified to be well formed and the
same error always occurs. Therefore, I think it could be a bug.
To be sure, I used the SAXParser in the JAXP API and had no problems parsing
the same files.
##############################################################################
import java.io.*;
import java.util.*;
import java.net.*;
import org.xml.sax.SAXException;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;
import org.apache.xerces.parsers.SAXParser;
public class TestParse {
public TestParse() {
}
public static void main(String args[]){
StringBuffer debugText = new StringBuffer();
String line = null;
InputStream input = null;
try {
SAXParser saxParser = new SAXParser();
saxParser.setContentHandler(new TestContentHandler());
input = ClassLoader.getSystemClassLoader
().getResourceAsStream("myxmlfile.xml");
InputStreamReader inputReader = new InputStreamReader
(input);
BufferedReader buffReader = new BufferedReader
(inputReader);
line = buffReader.readLine();
do {
System.out.println(line);
line = buffReader.readLine();
} while (line != null);
InputSource source = new InputSource(input);
saxParser.parse(source);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
##############################################################################
import org.xml.sax.*;
import org.xml.sax.helpers.*;
public class TestContentHandler extends DefaultHandler {
public TestContentHandler() {
}
//===========================================================
// SAX DocumentHandler methods
//===========================================================
public void startDocument() throws SAXException {
System.out.println("startDocument()");
}
public void endDocument() throws SAXException {
System.out.println("endDocument()");
}
public void startElement(String namespaceURI,
String lName, // local name
String qName, // qualified name
Attributes attrs) throws SAXException {
System.out.println("startElement()");
}
public void endElement(String namespaceURI,
String sName, // simple name
String qName // qualified name
) throws SAXException {
System.out.println("endElement");
}
public void characters(char buf[], int offset, int len) throws
SAXException {
String s = new String(buf, offset, len);
System.out.println("characters");
}
public void ignorableWhitespace(char buf[], int offset, int len) throws
SAXException {
String s = new String(buf, offset, len);
System.out.println("ignorableWhitespace");
}
}
##############################################################################
org.xml.sax.SAXParseException: The root element is required in a well-formed
document.
at org.apache.xerces.framework.XMLParser.reportError
(XMLParser.java:1196)
at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError
(XMLDocumentScanner.java:570)
at
org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.endOfInput
(XMLDocumentScanner.java:790)
at org.apache.xerces.framework.XMLDocumentScanner.endOfInput
(XMLDocumentScanner.java:418)
at
org.apache.xerces.validators.common.XMLValidator.sendEndOfInputNotifications
(XMLValidator.java:694)
at org.apache.xerces.readers.DefaultEntityHandler.changeReaders
(DefaultEntityHandler.java:1026)
at org.apache.xerces.readers.XMLEntityReader.changeReaders
(XMLEntityReader.java:168)
at org.apache.xerces.readers.UTF8Reader.changeReaders
(UTF8Reader.java:182)
at org.apache.xerces.readers.UTF8Reader.lookingAtChar
(UTF8Reader.java:197)
at
org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.dispatch
(XMLDocumentScanner.java:686)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome
(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1081)
at TestParse.main(TestParse.java:30)
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org