简体   繁体   English

xml:元素的值无效

[英]xml:The value of the element is not valid

I have created the xsd file using eclipse tool also I have created the xml file using that xsd file in the same tool. 我使用eclipse工具创建了xsd文件,我也在同一工具中使用该xsd文件创建了xml文件。 I am not able to recognize this errors. 我无法识别这个错误。

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.

According to my analysis it's all right and well following the xsd file. 根据我的分析,它很好,并且遵循xsd文件。

Here is my xsd file : 这是我的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>

Here is my resultant xml file from xsd file. 这是我从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>

Found the mistakes , it took me hours to correct but finally ended up fixing it. 发现错误,我花了几个小时来纠正,但最终结束了修复。

here it goes the right 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" >
   <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>

Change is simpleType- lenght to MaxLength and also placing the product element in proper hierarchy. 更改是simpleType-lenght到MaxLength,并且还将product元素放在适当的层次结构中。

so resultant xml would be like this with no errors:- 所以结果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>

Thanks for all the viewers :) 感谢所有观众:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM