[jdom-interest] Can't get JDOM to work with the Objects, Objects Everywhere XML a
nd Schema examples
Emmanuel, Peter BGI WAC
Peter.Emmanuel at barclaysglobal.com
Fri Nov 3 16:11:39 PST 2000
I have been reading Brett's excellent article on Objects, objects everywhere
and decided that it was time that I started trying to use JDOM on upcoming
projects. I wrote this very simple test code which works fine until I use
validation which then produces different errors (depending on what's done to
the XML and/or Schema documents).
I would really, really appreciate all the help as I am trying to use JDOM to
handle my XML docs (which I also am trying to use Schema to validate
against). Also, if anyone has gotten that example to work would you send me
your XML, Schema docs?
Thanks in advance,
Peter Emmanuel
peter.emmanuel at barclaysglobal.com <mailto:peter.emmanuel at barclaysglobal.com>
Here is my TestCode:
SAXBuilder builder = new SAXBuilder(true);
Document doc = builder.build(new
File("C:\0_myprojects\src\xml\example.xml"));
XMLOutputter fmt = new XMLOutputter();
fmt.output(doc, System.out);
If I were to use the XML and schema files exactly as is, I get this error:
org.jdom.JDOMException: General Schema Error: Grammar with uri :
http://www.enhydra.org , can not found.:
Error on line 10 of document file:/C:/0_myprojects/src/xml/example.xml:
General Schema Error: Grammar with uri : http://www.enhydra.org , can not
found.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:310)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:373)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
at jTest.xmlBinding.TestJDom.<init>(TestJDom.java:28)
at jTest.xmlBinding.TestJDom.main(TestJDom.java:17)
Root cause: org.jdom.JDOMException: Error on line 10 of document
file:/C:/0_myprojects/src/xml/example.xml:
General Schema Error: Grammar with uri : http://www.enhydra.org , can not
found.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:311)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:373)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
at jTest.xmlBinding.TestJDom.<init>(TestJDom.java:28)
at jTest.xmlBinding.TestJDom.main(TestJDom.java:17)
This is the XML file as is:
<?xml version="1.0"?>
<webServiceConfiguration xmlns="http://www.enhydra.org"
xmlns:xsi="http://www.w3.org/1999/XMLSchema/instance"
xsi:schemaLocation="http://www.enhydra.org configuration.xsd"
version="1.1" name="Unsecured Web Listener">
<port number="80" protocol="http" protectedPort="false" />
<document root="/usr/local/enhydra/html" index="*.html,*.xml"
error="error.html" />
</webServiceConfiguration>
And here is the Schema file as is:
<?xml version="1.0"?>
<schema targetNamespace="http://www.enhydra.org"
xmlns="http://www.w3.org/1999/XMLSchema"
xmlns:enhydra="http://www.enhydra.org"
>
<complexType name="ServiceConfiguration">
<attribute name="name" type="string" />
<attribute name="version" type="float" />
</complexType>
<element name="serviceConfiguration" type="ServiceConfiguration" />
<complexType name="WebServiceConfiguration"
baseType="ServiceConfiguration"
derivedBy="extension">
<element name="port">
<complexType>
<attribute name="protocol" type="string" />
<attribute name="number" type="integer" />
<attribute name="protectedPort" type="string" />
</complexType>
</element>
<element name="document">
<complexType>
<attribute name="root" type="string" />
<attribute name="index" type="string" />
<attribute name="error" type="string" />
</complexType>
</element>
</complexType>
<element name="webServiceConfiguration" type="WebServiceConfiguration" />
</schema>
When I modified the file to remove the "http://www.enhydra.org
<http://www.enhydra.org> " namespace I get this error:
C:\0_myprojects\src\>java -cp
.;..\..\classes;C:\0_myprojects\lib\jdom.jar;C:\0_myprojects\lib\xerces.jar
-D=..\..\classes jTest.xmlBinding.TestJDom
C:\0_myprojects\src\xml\example.xml
org.jdom.JDOMException: Element type "webServiceConfiguration" must be
declared.: Error on line 7 of document
file:/C:/0_myprojects/src/xml/example.xml: Element type
"webServiceConfiguration" must be declared.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:310)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:373)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
at jTest.xmlBinding.TestJDom.<init>(TestJDom.java:28)
at jTest.xmlBinding.TestJDom.main(TestJDom.java:17)
Root cause: org.jdom.JDOMException: Error on line 7 of document
file:/C:/0_myprojects/src/xml/example.xml:
Element type "webServiceConfiguration" must be declared.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:311)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:373)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
at jTest.xmlBinding.TestJDom.<init>(TestJDom.java:28)
at jTest.xmlBinding.TestJDom.main(TestJDom.java:17)
And here is the modified XML file:
<?xml version="1.0"?>
<webServiceConfiguration
xmlns:xsi="http://www.w3.org/1999/XMLSchema/instance"
xsi:noNamespaceSchemaLocation="configuration.xsd" version="1.1"
name="Unsecured Web Listener">
<port number="80" protocol="http" protectedPort="false"/>
<document root="/usr/local/enhydra/html" index="*.html,*.xml"
error="error.html"/>
</webServiceConfiguration>
And here is my modified Schema:
<?xml version="1.0" encoding="UTF-8"?>
<schema>
<complexType name="ServiceConfiguration">
<attribute name="name" type="string"/>
<attribute name="version" type="float"/>
</complexType>
<element name="serviceConfiguration" type="ServiceConfiguration"/>
<complexType name="WebServiceConfiguration"
base="ServiceConfiguration" derivedBy="extension">
<element name="port">
<complexType>
<attribute name="protocol" type="string"/>
<attribute name="number" type="integer"/>
<attribute name="protectedPort"
type="string"/>
</complexType>
</element>
<element name="document">
<complexType>
<attribute name="root" type="string"/>
<attribute name="index" type="string"/>
<attribute name="error" type="string"/>
</complexType>
</element>
</complexType>
<element name="webServiceConfiguration"
type="WebServiceConfiguration"/>
</schema>
And lastly (if you get this far), I tried using my own namespace and get
this error instead:
org.xml.sax.SAXParseException: Schema error: complexType
'ServiceConfiguration' with a elementOnly or mixed content need to have at
least one particle child.
at
org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1016)
at
org.apache.xerces.validators.schema.TraverseSchema.reportSchemaError(Travers
eSchema.java, Compiled Code)
at
org.apache.xerces.validators.schema.TraverseSchema.reportGenericSchemaError(
TraverseSchema.java:4342)
at
org.apache.xerces.validators.schema.TraverseSchema.traverseComplexTypeDecl(T
raverseSchema.java, Compiled Code)
at
org.apache.xerces.validators.schema.TraverseSchema.doTraverseSchema(Traverse
Schema.java, Compiled Code)
at
org.apache.xerces.validators.schema.TraverseSchema.<init>(TraverseSchema.jav
a:497)
at
org.apache.xerces.validators.common.XMLValidator.resolveSchemaGrammar(XMLVal
idator.java:2238)
at
org.apache.xerces.validators.common.XMLValidator.bindNamespacesToElementAndA
ttributes(XMLValidator.java, Compiled Code)
at
org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidat
or.java, Compiled Code)
at
org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanne
r.java, Compiled Code)
at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XM
LDocumentScanner.java, Compiled Code)
at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.
java, Compiled Code)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:302)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:373)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
at jTest.xmlBinding.TestJDom.<init>(TestJDom.java:28)
at jTest.xmlBinding.TestJDom.main(TestJDom.java:17)
org.jdom.JDOMException: Element type "webServiceConfiguration" must be
declared.: Error on line 4 of document
file:/C:/0_myprojects/src/BGIS/xml/example.xml: El
ement type "webServiceConfiguration" must be declared.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:310)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:373)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
at jTest.xmlBinding.TestJDom.<init>(TestJDom.java:28)
at jTest.xmlBinding.TestJDom.main(TestJDom.java:17)
Root cause: org.jdom.JDOMException: Error on line 4 of document
file:/C:/0_myprojects/src/BGIS/xml/example.xml: Element type
"webServiceConfiguration" must be d
eclared.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:311)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:373)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
at jTest.xmlBinding.TestJDom.<init>(TestJDom.java:28)
at jTest.xmlBinding.TestJDom.main(TestJDom.java:17)
And here is the XML doc:
<?xml version="1.0" encoding="UTF-8"?>
<webServiceConfiguration xmlns="http://www.barclaysglobal.com"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:schemaLocation="http://www.barclaysglobal.com configuration.xsd"
name="Unsecured Web Listener" version="1.1">
<port number="80" protocol="http" protectedPort="false"/>
<document root="/usr/local/enhydra/html" index="*.html,*.xml"
error="error.html"/>
</webServiceConfiguration>
And its corresponding Schema:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.barclaysglobal.com"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns="http://www.barclaysglobal.com">
<xsd:complexType name="ServiceConfiguration">
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="version" type="xsd:float"/>
</xsd:complexType>
<xsd:element name="serviceConfiguration"
type="ServiceConfiguration"/>
<xsd:complexType name="WebServiceConfiguration"
base="ServiceConfiguration" derivedBy="extension">
<xsd:element name="port">
<xsd:complexType>
<xsd:attribute name="protocol"
type="xsd:string"/>
<xsd:attribute name="number"
type="xsd:integer"/>
<xsd:attribute name="protectedPort"
type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="document">
<xsd:complexType>
<xsd:attribute name="root"
type="xsd:string"/>
<xsd:attribute name="index"
type="xsd:string"/>
<xsd:attribute name="error"
type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:complexType>
<xsd:element name="webServiceConfiguration"
type="WebServiceConfiguration"/>
</xsd:schema>
More information about the jdom-interest
mailing list