加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

验证xml架构时出错

发布时间:2020-12-16 07:47:32 所属栏目:百科 来源:网络整理
导读:我想为一个空的元素制作一个简单的模式 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="h
我想为一个空的元素制作一个简单的模式
<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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读