Hi Jasbir,
Following is the right XML file::
<?xml version="1.0" ?>
<Request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="jasbir.xsd">
<Transaction xsi:type="_Transaction_Login">
<user_id>test</user_id>
<password>xxx</password>
</Transaction>
</Request>
Also, as u dont have DTD, so set the DTD feature to false , and true for Schema
xr.setFeature( "http://xml.org/sax/features/validation",false);
xr.setFeature( "http://xml.org/sax/features/namespaces",true);
xr.setFeature( "http://apache.org/xml/features/validation/schema",true);
Regds,
Anoop Singh
-----Original Message-----
From: jasbir.matharu@hfcbank.co.uk [mailto:jasbir.matharu@hfcbank.co.uk]
Sent: Tue 12/17/2002 4:58 PM
To: xerces-j-dev@xml.apache.org
Cc:
Subject: Schema validation problem with xsi:type
I have problems when attempting to use the xsi:type parameter in a schema
with Xerces. Here is a sample schema.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="_Transaction" abstract="true">
<xs:sequence>
<xs:element name="user_id"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="_Transaction_Login">
<xs:complexContent>
<xs:extension base="_Transaction">
<xs:sequence>
<xs:element name="password"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="_Transaction_Submit">
<xs:complexContent>
<xs:extension base="_Transaction">
<xs:sequence>
<xs:element name="application_number">
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Request">
<xs:complexType name="">
<xs:sequence>
<xs:element name="Transaction" type="_Transaction"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
If I validate it with the following XML in XML Spy then it works fine.
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Transaction xsi:type="_Transaction_Login">
<user_id>test</user_id>
<password>xxx</password>
</Transaction>
</Request>
Under Xerces it reports the following error
Parsing error: Document root element "Request", must match DOCTYPE root
"null".
Parsing error: Document is invalid: no grammar found.
The test code I'm using is
this._parser = new SAXParser();
this._parser.setFeature
("http://xml.org/sax/features/validation",true);
this._parser.setProperty
("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
"/test/test3.xsd");
this._parser.setErrorHandler(this.new B2BSaxHandler());
String xml = "<Request xmlns:xsi
=\"http://www.w3.org/2001/XMLSchema-instance\">"+
"<Transaction xsi:type=\"_Transaction_Login\">"+
"<user_id>test</user_id>"+
"<password>xxx</password>"+
"</Transaction>"+
"</Request>";
System.out.println(xml);
StringReader data = new StringReader(xml);
_parser.parse(new org.xml.sax.InputSource(data));
_parser.reset();
Any help is appreciated!
Jasbir
|
| Mime |
- Unnamed multipart/mixed (inline, None, 0 bytes)
|