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 Martijn Lindhout <ma...@hetnet.nl> on 2000/07/10 13:15:59 UTC
URGENT: Validation in DOM Parser doesn't work!
Hello,
Please HELP me! This is urgent for a system in production!
I use the Xerces DOMParser to validate my documents. According to the sample
in the documentation I did the following to validate a doc using a schema:
DOMParser parser = new DOMParser();
FileInputStream instream = new FileInputStream("SayHello.xml");
parser.setIncludeIgnorableWhitespace(false);
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.parse(new InputSource(instream));
Document document = parser.getDocument();
I executed the code with the folowing XML Doc:
<?xml version="1.0" encoding="UTF-8"?>
<SayHelloA xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="SayHello.xsd">
<SayHello>
<INPUT>Hello world! The XML interface works!</INPUT>
</SayHello>
</SayHelloA>
and this schema:
<?xml version='1.0' encoding='UTF-8'?>
<schema>
<element name='SayHelloA'>
<type>
<element ref='SayHello' minOccurs='1' maxOccurs='1'/>
<attribute name='xmlns'/>
</type>
</element>
<element name='SayHello'>
<type>
<element ref='INPUT' minOccurs='1' maxOccurs='1'/>
</type>
</element>
<element name='INPUT' type='string'/>
</schema>
When I run the program, the following parser error occurs:
[Error 3,22]: Attribute "xmlns:xsi" must be declared for element type
"SayHelloA".
Why? According to the documentation, I have to use the xsi: prefix.