2017-03-15 109 views
1

我已经使用eclipse工具创建了xsd文件,我也在同一个工具中使用该xsd文件创建了xml文件。我无法识别这个错误。xml:元素的值无效

cvc-type.3.1.3: The value 'tns:name' of element 'tns:name' is not valid. 

cvc-type.3.1.3: The value 'tns:description' of element 'tns:description' is not valid. 

根据我的分析,它是好的,并遵循xsd文件。

这里是我的xsd文件:

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.jaggorder.org/order" 
    xmlns:tns="http://www.jaggorder.org/order" 
    elementFormDefault="qualified"> 

    <element name="order" type="tns:order"></element> 
    <complexType name="order"> 
    <sequence> 
    <element name= "product" type = "string"></element> 
    <sequence> 
    <element name= "name" type = "tns:name_rs"></element> 
    <element name= "description" type = "tns:desp"></element> 
    <element name= "price" type = "int"></element> 
     <element name= "category" type = "string"></element> 

    </sequence> 
    </sequence> 
</complexType> 

    <simpleType name="name_rs"> 
    <restriction base="string"> 
    <length value="20"></length></restriction> 
    </simpleType> 

    <simpleType name="desp"> 
    <restriction base="string"> 
    <length value="100"></length></restriction> 
    </simpleType> 

    <simpleType name="category_en"> 
    <restriction base="string"> 
    <enumeration value="electronics"></enumeration> 
    <enumeration value="Books"></enumeration> 
    <enumeration value="shoes"></enumeration> 
    </restriction> 
    </simpleType> 



</schema> 

下面是从XSD文件我生成的XML文件。

<?xml version="1.0" encoding="UTF-8"?> 
<tns:order xmlns:tns="http://www.jaggorder.org/order" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jaggorder.org/order order.xsd "> 
    <tns:product>tns:product</tns:product> 
    <tns:name>tns:name</tns:name> 
    <tns:description>tns:description</tns:description> 
    <tns:price>0</tns:price> 
    <tns:category>tns:category</tns:category> 
</tns:order> 

回答

0

发现了错误,它花了我几个小时来纠正,但最后终于修复它。

这里去正确的xsd: -

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.jaggorder.org/order" 
    xmlns:tns="http://www.jaggorder.org/order" 
    elementFormDefault="qualified"> 

    <element name="order" type="tns:order"></element> 
    <complexType name="order"> 
    <sequence> 
    <element name= "product" > 
    <complexType> 
    <sequence> 
    <element name= "name" type = "tns:name_rs"></element> 
    <element name= "description" type = "tns:desp"></element> 
    <element name= "price" type = "int"></element> 
     <element name= "category" type = "tns:category_en"></element> 
    </sequence> 
    </complexType> 
    </element> 
    </sequence> 
</complexType> 

    <simpleType name="name_rs"> 
    <restriction base="string"> 
    <maxLength value="20"></maxLength></restriction> 
    </simpleType> 

    <simpleType name="desp"> 
    <restriction base="string"> 
    <maxLength value="100"></maxLength></restriction> 
    </simpleType> 

    <simpleType name="category_en"> 
    <restriction base="string"> 
    <enumeration value="electronics"></enumeration> 
    <enumeration value="Books"></enumeration> 
    <enumeration value="shoes"></enumeration> 
    </restriction> 
    </simpleType> 



</schema> 

变化是simpleType- lenght到的MaxLength也将产品元素适当的层次。

这样生成的XML会是这样的,没有错误: -

<?xml version="1.0" encoding="UTF-8"?> 
<tns:order xmlns:tns="http://www.jaggorder.org/order" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.jaggorder.org/order order.xsd "> 
    <tns:product> 
    <tns:name>tns:name</tns:name> 
    <tns:description>description</tns:description> 
    <tns:price>0</tns:price> 
    <tns:category>Books</tns:category> 
    </tns:product> 
</tns:order> 

感谢所有观众:)