验证xml架构时出错

验证xml架构时出错,xml,schema,Xml,Schema,我想为空元素创建一个简单的模式 <product orderid="4"/> 如果您更改XSD并放入xmlns=”http://xml.netbeans.org/schema/first“在xsd:schema元素中,它应该可以工作(它为我做了)这将起作用,在类型中添加'tns:” <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.netbeans

我想为空元素创建一个简单的模式

 <product orderid="4"/>

如果您更改XSD并放入
xmlns=”http://xml.netbeans.org/schema/first“
xsd:schema
元素中,它应该可以工作(它为我做了)

这将起作用,在类型中添加'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中定义。为了引用它,您需要包括中定义的命名空间。在您的示例中,您试图引用默认命名空间中未定义的prodtype。

顺便说一句,
xsd:schema
在您的上述代码中未关闭,这可能与此相关吗?不,这只是格式错误,此代码与我一起工作,但在从xmlns:tns=”中删除“tns”后,我直到现在才理解原因!回答得很好,这是对@jeremyhare的补充。
 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'.
<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>