[jdom-interest] XML Schema problem
Eric
e.macaulay at cs.ucl.ac.uk
Wed Aug 22 04:23:27 PDT 2001
I have defined the following schema, test.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="test" type="xsd:string"/>
</xsd:schema>
I have also defined the following xml file, test.xml:
<?xml version="1.0"?>
<test
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/XMLSchema test.xsd"/>
However when I run the following program MyParser.java:
try {
SAXBuilder builder = new SAXBuilder(true);
Document doc = builder.build(new File("test.xml"));
XMLOutputter xmlout = new XMLOutputter();
xmlout.output(doc, System.out);
}catch (JDOMException jex) {
jex.printStackTrace();
}catch (IOException iex) {
iex.printStackTrace();
}
I get the following exception:
org.jdom.JDOMException: Error on line 4 of document
file:/C:/PRACTICE/XML/test.xml:
Element type "test" must be declared.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:296)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:617)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:599)
at MyParser.main(MyParser.java:20)
Root cause: org.xml.sax.SAXParseException: Element type "test" must be
declared
.
at
org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1008
)
at
org.apache.xerces.validators.common.XMLValidator.reportRecoverableXML
Error(XMLValidator.java:1236)
at
org.apache.xerces.validators.common.XMLValidator.validateElementAndAt
tributes(XMLValidator.java:2673)
at
org.apache.xerces.validators.common.XMLValidator.callStartElement(XML
Validator.java:818)
at
org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumen
tScanner.java:1852)
at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.disp
atch(XMLDocumentScanner.java:1000)
at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS
canner.java:380)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:287)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:617)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:599)
at MyParser.main(ClassParser.java:20)
I am using jdom beta 7. can anyone help?
Thanks,
Eric M.
More information about the jdom-interest
mailing list