Hi people,
 
I encountered a very strange problems. I am using Xerces version 1.0.4. I am using SAXParser
 
First example
 
I had the following Schema: (file name: schema1.xsd)
 

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified
">
        <xsd:element name="Vars
">
                <xsd:complexType
>
                        <xsd:sequence
>
                                <xsd:element name="Var
">
                                        <xsd:complexType mixed="true
">
                                                <xsd:attribute name="name
"/>
                                        </xsd:complexType
>
                                </xsd:element
>
                        </xsd:sequence
>
        </xsd:complexType
>
</xsd:element
>
</
xsd:schema>

And I had the following XML code:

<?xml version="1.0" encoding="UTF-8"?>
<Vars xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema1.xsd">

        <Var name="myVar
">
                5
        </Var
>
</
Vars>

And I got the following exception during validation process!!

Error on line 2: Element type "Vars" must be declared.
org.jdom.JDOMException: Error on line 2: Element type "Vars" must be declared.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:407)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:499)
at saxParser.Main.main(Main.java:50)
Root cause: org.xml.sax.SAXParseException: Element type "Vars" must be declared.
at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1060)
at org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(XMLValidator.java:1432)
at org.apache.xerces.validators.common.XMLValidator.validateElementAndAttributes(XMLValidator.java:2930)
at org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:924)
at org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1858)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1001)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:952)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:395)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:499)
at saxParser.Main.main(Main.java:50)

What is wrong?

Second example

I used the previous version of the Xerces and I made the following changes (colored bold blue) in the Schema and the XML, and I got no exception during the validation process.

Schema:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" elementFormDefault="qualified
">
        <xsd:element name="Vars
">
                <xsd:complexType
>
                        <xsd:sequence
>
                                <xsd:element name="Var
">
                                        <xsd:complexType mixed="true
">
                                                <xsd:attribute name="name
"/>
                                        </xsd:complexType
>
                                </xsd:element
>
                        </xsd:sequence
>
        </xsd:complexType
>
</xsd:element
>
</
xsd:schema>

XML code:

<?xml version="1.0" encoding="UTF-8"?>
<Vars xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema1.xsd">

        <Var name="myVar
">
                5
        </Var
>
</
Vars>

As I said the above example works ok, with no exceptions.
By the way, I tried to run the second example with the latest version of Xerces but I got the same exception as in the first example.
One last thing, the first example results the same exception when I tried to run it using the previous version of Xerces.

I also noticed that in the different samples in "Apache" site, the syntax that I used in the first example is used with the latest version of the Xerces.

What is wrong?

I am really confused with that.

Thank you for the help.

Ala

 

Reply via email to