微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

XML模式命名空间.验证根目录没有可用的匹配全局声明

使用命名空间时引用模式时的正确语法是什么?

问题

使用给定模式创建XML文档.

错误

.xml:9.20: Element '{http://example/buildings/1.0}old_buildings': No matching global declaration available for the validation root.
    oldbuildings.xml - invalid
    Problem

XML文档

<?xml version="1.0" encoding="UTF-8"?>

<buildings:old_buildings xmlns:buildings="http://example/buildings/1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://example/buildings/1.0 oldbuildings_schema.xsd">
    <building>
        <name>Name</name>
        <year_built era="BC">2000</year_built>
        <story>...<story>
    </building>
</buildings:old_buildings>

XSD文件


    <?xml version="1.0" encoding="UTF-8"?>

    <xs:schema targetNamespace="http://example/buildings/1.0/" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://example/buildings/1.0/"> <xs:element name="old_buildings"> <xs:complexType> <xs:sequence> <xs:element ref="building"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="building" type="buildingType"></xs:element> <xs:complexType name="buildingType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="year_built" type="yearType"/> <xs:element name="story" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="yearType"> <xs:simpleContent> <xs:extension base="xs:positiveInteger"> <xs:attribute name="era" type="xs:string"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <buildings:old_buildings xmlns:buildings="http://example/buildings/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://example/buildings/1.0 oldbuildings_schema.xsd"> <building> <name>Name</name> <year_built era="BC">2000</year_built> <story>...<story> </building> </buildings:old_buildings>

解决方法

在您的xml文件中,尝试使用

xmlns:buildings="http://example/buildings/1.0/"

使用/ final,如在xsd声明中:xs:schema targetNamespace =“http://example/buildings/1.0/”

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。