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