例外:src-resolve.4.2:解析xsd中的组件时出错

时间:2013-10-29 14:06:19

标签: xml xsd

我正在尝试针对xsd验证xml。以下是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>

我收到以下异常。请帮助我理解我缺少的是什么

异常:src-resolve.4.2:解析组件'contactNumberType'时出错。

1 个答案:

答案 0 :(得分:6)

鉴于创作方法,您必须确保默认命名空间(xmlns属性的值)与targetNamespace属性的值匹配。

当您按名称引用类型,属性,attributeGroup,元素或组时,该名称是限定名称。如果您引用的名称没有前缀,则假定它在默认命名空间中(如果已指定)或根本没有命名空间。默认名称空间为http://www.w3schools.com,处理器正在寻找{http://www.w3schools.com} contactNumberType;您的XSD定义了{http://www.xxxxxxxxxxxxx/xxxxxxxx} contactNumberType,显然不匹配。修复默认命名空间,修复您的引用。

xmlns="http://www.xxxxxxxxxxxxx/xxxxxxxx" targetNamespace="http://www.xxxxxxxxxxxxx/xxxxxxxx"