验证xml架构时出错

前端之家收集整理的这篇文章主要介绍了验证xml架构时出错前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想为一个空的元素制作一个简单的模式
<product orderid="4"/>

我像这样创建了我的XSD:

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


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/first"
xmlns:tns="http://xml.netbeans.org/schema/first"
elementFormDefault="qualified">

<xsd:element name="product" type="prodtype"/>
<xsd:complexType name="prodtype">
        <xsd:attribute name="prodid" type="xsd:integer"/>
</xsd:complexType>

</xsd:schema>

在针对XSD验证XML时出现以下错误

Error resolving component 'prodtype'. It was detected that 'prodtype' has no namespace,but components with no target namespace are not referenceable from schema document 'file:/D:/Teacher%20assistant%202011/First%20term/web%20services/test%20programs/BpelModule1/src/product.xsd'. If 'prodtype' is intended to have a namespace,perhaps a prefix needs to be provided. If it is intended that 'prodtype' has no namespace,then an 'import' without a "namespace" attribute should be added to 'file:/D:/Teacher%20assistant%202011/First%20term/web%20services/test%20programs/BpelModule1/src/product.xsd'.
这将有效,将“tns:”添加到类型中.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://xml.netbeans.org/schema/first"
    xmlns:tns="http://xml.netbeans.org/schema/first"
    elementFormDefault="qualified">    
    <xsd:element name="product" type="tns:prodtype"/>
    <xsd:complexType name="prodtype">
        <xsd:attribute name="prodid" type="xsd:integer"/>
    </xsd:complexType>    
</xsd:schema>

prodtype在架构的targetNamespace中定义,在本例中为“http://xml.netbeans.org/schema/first”.为了引用它,您需要包含定义的命名空间.在您的示例中,尝试引用未定义的默认命名空间中的prodtype.

原文链接:https://www.f2er.com/xml/292500.html

猜你在找的XML相关文章