[jdom-interest] Problems with validation against schemas
Jose_Sanchez at amsinc.com
Jose_Sanchez at amsinc.com
Thu Aug 31 11:28:01 PDT 2000
Hi,
I'm trying to parse xml with schema validation using Xerces 1.2.1 and JDOM
1.0. It seems that there is something wrong in my xml schema cause I keep on
getting this error:
org.jdom.JDOMException: Element type "config" must be declared.: Error on line 2
of document file:/C:/WINNT/Profiles/sanchezj/jbproject/ErrorHandler/delete.xml:
Element type "config" must be declared.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:279)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:345)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:326)
at CommandEngine.main(CommandEngine.java:70)
Root cause: org.jdom.JDOMException: Error on line 2 of document
file:/C:/WINNT/Profiles/sanchezj/jbproject/ErrorHandler/delete.xml: Element type
"config" must be declared.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:280)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:345)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:326)
at CommandEngine.main(CommandEngine.java:70)
Here's the code I use:
import java.io.File;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
public class CommandEngine{
public static void main(String[] args) throws Exception {
SAXBuilder builder = new SAXBuilder(true);
try {
Document doc = builder.build(new File("delete.xml"));
} catch (JDOMException e) {
e.printStackTrace();
}
}
}
And here are the delete.xml and delete.xsd:
delete.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="delete.xsd">
<common>
<timeout>200</timeout>
</common>
<specific>
<timein>196</timein>
</specific>
</config>
delete.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<xsd:complexType name="commonType" content="elementOnly">
<xsd:sequence>
<xsd:element name="timeout" type="xsd:short"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="config">
<xsd:complexType content="elementOnly">
<xsd:sequence>
<xsd:element name="common" type="commonType"/>
<xsd:element name="specific" type="specificType"/>
</xsd:sequence>
<xsd:attribute name="xmlns:xsi" type="xsd:uriReference" use="default"
value="http://www.w3.org/1999/XMLSchema-instance"/>
<xsd:attribute name="xsi:noNamespaceSchemaLocation" type="xsd:string"/>
<xsd:attribute name="xsi:schemaLocation" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="specificType" content="elementOnly">
<xsd:sequence>
<xsd:element name="timein" type="xsd:short"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
I'm using XML Spy 3.0 for generating both the .xml and .xsd and validate the
delete.xml against the delete.xsd...and it does validate. So please, let me know
if I'm making any stupid error or if any of you have experinced the same type of
problems. Thanks very much in advance,
Jose
More information about the jdom-interest
mailing list