xml - 此命名空间中的组件无法从架构文档中引用

标签 xml xsd namespaces xml-namespaces

我知道关于这个主题有很多问题,我已经研究了其中的很多问题。但从我读到的所有内容来看,我的模式看起来是正确的。但当我尝试验证架构时,我仍然收到此错误:

org.xml.sax.SAXParseException: src-resolve.4.2: Error resolving component 'addr:coordinatesElement'. It was detected that 'addr:coordinatesElement' is in namespace 'urn:ajga.address:1.0', but components from this namespace are not referenceable from schema document 'file:///C:/Users/tmcginnis/Workspaces/MyEclipse%202015%20CI/nanda-schema-0.0.1-SNAPSHOT/src/main/resources/schema/AddressSchema_1_0.xsd'. If this is the incorrect namespace, perhaps the prefix of 'addr:coordinatesElement' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:///C:/Users/tmcginnis/Workspaces/MyEclipse%202015%20CI/nanda-schema-0.0.1-SNAPSHOT/src/main/resources/schema/AddressSchema_1_0.xsd'.

这是架构:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="urn:ajga:address:1.0"
    xmlns:tns="urn:ajga.address:1.0"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    version="1.0">
    <xsd:element name="address">
        <xsd:complexType>
            <xsd:all>
                <xsd:element name="addressType" type="xsd:string" minOccurs="0"/>
                <xsd:element name="addressLine1" type="xsd:string"/>
                <xsd:element name="addressLine2" type="xsd:string" minOccurs="0"/>
                <xsd:element name="pobox" type="xsd:string" minOccurs="0"/>
                <xsd:element name="city" type="xsd:string"/>
                <xsd:element name="state" type="xsd:string"/>
                <xsd:element name="zip" type="xsd:string"/>
                <xsd:element name="countyCode" type="xsd:string" minOccurs="0"/>
                <xsd:element name="country" type="xsd:string"/>
                <xsd:element name="fips" type="xsd:string" minOccurs="0"/>
                <xsd:element name="coordinates" type="tns:coordinatesElement" minOccurs="0"/>
                <xsd:element name="description" type="xsd:string" minOccurs="0"/>
            </xsd:all>
        </xsd:complexType>
    </xsd:element>

    <xsd:complexType name="coordinatesElement">
        <xsd:all>
            <xsd:element name="longitude" type="xsd:string"/>
            <xsd:element name="lattitude" type="xsd:string"/>
        </xsd:all>
    </xsd:complexType>

</xsd:schema>

这有什么问题吗?

最佳答案

命名空间前缀 tns 应设置为与 targetNameSpace 属性相同的 URI。 请注意以下 URI 之间的区别:

targetNamespace="urn:ajga:address:1.0" 
                         ^ 
      xmlns:tns="urn:ajga.address:1.0"
                         ^   

关于xml - 此命名空间中的组件无法从架构文档中引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33901876/

相关文章:

c# - 在 web.config 文件中添加命名空间有什么好处?

c++ - 命名空间的类析构函数

xml - 在emacs中用一个键将html标签包裹在下一个单词周围

python - 在 pandas 中解析 XML

xml - 使用 XSL 将 XML 转换为 HTML 后无数据显示

XSD:xs:integer 和 xs:int 之间有什么区别?

xml - 使用 Drupal8 从 XML 文件导入数据

java - 异常 : cvc-type. 3.2.2:模式定义中的异常

c# - ArrayOfXElement 到 C# 中的数据集

asp.net - 将命名空间添加到现有项目 ASP.NET 2.0 C#