posted 23 years ago
Hi friends,
I am facing problem with parsing xml against schema using SAX2Parser with Xerces. I have created the xml file which has the following structure
<?xml version="1.0" encoding="UTF-8"?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\SchemaValidation\testschema.xsd">
<RoleNo>XI-12</RoleNo>
<Age>12</Age>
</Person>
Its corresponding schema is
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name ="Person">
<xsd:complexType>
<xsd:sequence >
<xsd:element name="RoleNo" type="xsd:string" />
<xsd:element name="Age" type="xsd:short"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
When I run the application to parse and validate, it checks for well-formedness correctly but does not validate against the schema. Instead gives the following error message:
Element Type "Person" must be declared.
Attribute "xsi:noNamespaceSchemaLocation" must be declared for element type "Person".
Element Type "RoleNo" must be declared.
Element Type "Age" must be declared.
I have the following
XMLReader parser;
parser = new SAXParser();
1. parser.setFeature(
"http://xml.org/sax/features/validation", true);
parser.setErrorHandler(new ValidityErrorReporter());
-------------->ValidityErrorReporter is my errorhandler class.
COULD NOT GET THROUGH BY THIS METHOD.
2.Tried to set the property by
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",parser.getProperty("http://apache.org/xml/properties/schema/external-noNamespaceSche maLocation"));
The method getProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation")
is not able to recognise the property "external-schemaLocation
" and "external-noNamespaceSchemaLocation".
Please respond to my query as soon as possible.
Thanks & Regards