Reputation: 743
I am tyring to validate a xml against a xsd. The following is the xsd
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns="http://www.w3schools.com" targetNamespace="http://www.xxxxxxxxxxxxx/xxxxxxxx" xmlns:cl="http://www.xxxxxx/contactlist" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:complexType name="contactNumberType">
<xsd:all>
<xsd:element name="type" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="number" type="xsd:integer" minOccurs="1" maxOccurs="1"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="contactNumbersType">
<xsd:sequence>
<xsd:element name="contact_number" type="contactNumberType" minOccurs="1" maxOccurs="2"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="contactType">
<xsd:all>
<xsd:element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="company" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="jobtitle" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="emailadress" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="addresses" type="addressesType" minOccurs="0" maxOccurs="1"/>
<xsd:element name="contact_numbers" type="contactNumbersType" minOccurs="1" maxOccurs="1"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="addressType">
<xsd:all>
<xsd:element name="type" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="street_address1" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="street_address2" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="suburb" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="postcode" type="xsd:integer" minOccurs="1" maxOccurs="1"/>
<xsd:element name="state" type="xsd:string" minOccurs="1" maxOccurs="1"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="contacts">
<xsd:sequence>
<xsd:element name="contact" type="contactType" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="addressesType">
<xsd:sequence>
<xsd:element name="address" type="addressType" minOccurs="1" maxOccurs="2"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
I am getting the following exception. Please help me understand what is that I am missing
Exception: src-resolve.4.2: Error resolving component 'contactNumberType'.
Upvotes: 2
Views: 10324
Reputation: 21638
Given the authoring approach, you have to make sure that the default namespace (xmlns attribute's value) matches the targetNamespace attribute's value.
When you reference a type, attribute, attributeGroup, element or group by name, that name is a qualified name. If the name you reference is without a prefix, then it is assumed to be in the default namespace, if specified, or no namespace at all. Having a default namespace of http://www.w3schools.com
, the processor is looking for {http://www.w3schools.com}contactNumberType; your XSD defines a {http://www.xxxxxxxxxxxxx/xxxxxxxx}contactNumberType, which obviously don't match. Fixing the default namespace, fixes your reference.
xmlns="http://www.xxxxxxxxxxxxx/xxxxxxxx" targetNamespace="http://www.xxxxxxxxxxxxx/xxxxxxxx"
Upvotes: 6