XML Schema Validation

I created following Schema Definition

<xs:schema xmlns:xs="[URL="http://www.w3.org/2001/XMLSchema"]http://www.w3.org/2001/XMLSchema[/URL]" xmlns="urn:transaction-schema" elementFormDefault="qualified" targetNamespace="urn:transaction-schema">
   <xs:simpleType name="FNameType">
  <xs:restriction base="xs:string">
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="AddressType">
  <xs:restriction base="xs:string">
  </xs:restriction>
 </xs:simpleType>
 <xs:complexType name="InformationType">
  <xs:sequence>
   <xs:element name="Name" type="FNameType" minOccurs="1" maxOccurs="1" />
         <xs:element name="Address" type="AddressType" minOccurs="1" maxOccurs="1" />
  </xs:sequence>
 </xs:complexType>
 <xs:element name="SampleDoc">
  <xs:complexType>
   <xs:sequence>
         <xs:element name="Information" type="InformationType" minOccurs="1" maxOccurs="10" />
         </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

Then I generated IS document type using this. Which created docType as well as IS schema for this XSD.

Then I generated sample xml for this schema using pub.xml.documentToXMLString, which gave me following output

<?xml version="1.0"?>
<ns:SampleDoc>
  <ns:Information>
    <ns:Name>MyName</ns:Name>
    <ns:Address>MyAddress</ns:Address>
  </ns:Information>
</ns:SampleDoc>

Please note that this xml does not have xmlns definition anywhere.

Now when I try to validate this xml against the schema that I generated previously it gives following error

pathName /
errorCode NV-001
[ISC.0082.9001] Error while parsing “[ISC.0042.9328] Error: namespace prefix ns not defined for element SampleDoc”

I tried to put the definition of ns in the sample xml and revaildate it.
Now it is giving following error.

Sample XML:

 
<?xml version="1.0"?>
<ns:SampleDoc xmlns:ns="[URL="http://www.thisserver.com/xmlSchemas"]http://www.thisserver.com/xmlSchemas[/URL]">
  <ns:Information>
    <ns:Name>MyName</ns:Name>
    <ns:Address>MyAddress</ns:Address>
  </ns:Information>
</ns:SampleDoc>

pathName /SampleDoc
errorCode NV-003
errorMessage [ISC.0082.9003] Unable to locate a matching element declaration

Why is this problem occuring if I have generated the sample xml from the same schema and then trying to revalidate against it?

Your schema is fine. Make sure you are setting the nsDecls parameter on your documenToXMLString service. THis is what sets up the namespace on the XML instance document. It should match what you have defined in your schema and also what was created in your documents. Which in this case you defined a default namespace of urn:transaction-schema, so the nsDecls should be ns for the prefix and urn:transaction-schema for the namespace.

Thanks Mark.
It is working :slight_smile:

Thanks Mark. It was helpful for me.

Hi All,

I am using xmlStringToXmlNode and to convert inciming xmlInput to node
And passing Node and schema path to pub.schema:validate service.
It is throwing error as below:
/ENVELOPE: [ISC.0082.9003] Unable to locate a matching element declaration;

Please help me to identify this error.