【问题标题】:Why am I getting this error "Invalid content with element catalog in xml"?为什么我会收到此错误“xml 中元素目录的内容无效”?
【发布时间】:2013-03-08 10:28:21
【问题描述】:

描述资源路径位置类型 cvc-complex-type.2.4.a:从元素“os:catalog”开始发现无效内容。需要 '{"http://www.example.org/objectshop":CatalogType}' 之一。 objectshop.xml /HelloWorld/WebContent 第 6 行 XML 问题

XSD 文件

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

    <complexType name="ProductType">
        <sequence>
            <element name="productId" type="string"></element>
            <element name="name" type="string"></element>
            <element name="description" type="string"></element>
            <element name="price" type="double"></element>
            <element name="campaignPrice" type="double"></element>
            <element name="icon" type="string"></element>
        </sequence>
    </complexType>

    <complexType name="CustomerType">
        <sequence>
            <element name="userId" type="string"></element>
            <element name="name" type="string"></element>
            <element name="address" type="string"></element>
            <element name="phone" type="string"></element>
            <element name="email" type="string"></element>
        </sequence>
    </complexType>

    <complexType name="CatalogType">
        <sequence>
            <element name="ProductType" type="os:ProductType"
                minOccurs="0" maxOccurs="unbounded">
            </element>
        </sequence>
    </complexType>

    <complexType name="MembersType">
        <sequence>
            <element name="customer" type="os:CustomerType" minOccurs="0" maxOccurs="unbounded"></element>
        </sequence>
    </complexType>

    <element name="objectshop" type="os:ObjectShopType"></element>

    <complexType name="ObjectShopType">
        <sequence>
            <element name="CatalogType" type="os:CatalogType"></element>
            <element name="MembersType" type="os:MembersType"></element>
        </sequence>
    </complexType>
</schema>

XML 文件

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="objectshop.xsl" ?>
<os:objectshop xmlns:os="http://www.example.org/objectshop"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.example.org/objectshop objectshop.xsd ">
  <os:catalog>
    <os:product>
        <os:productId>1</os:productId>
        <os:name>Achtung Baby - U2</os:name>
        <os:description>Audio CD</os:description>
        <os:price>21.0</os:price>
        <os:campaignPrice>19.0</os:campaignPrice>
        <os:icon>images/u2AchtungBaby.jpg</os:icon>
    </os:product>
    <os:product>
        <os:productId>2</os:productId>
        <os:name>Achtung Baby - U2</os:name>
        <os:description>Audio CD</os:description>
        <os:price>21.0</os:price>
        <os:campaignPrice>19.0</os:campaignPrice>
        <os:icon>images/u2AchtungBaby.jpg</os:icon>
    </os:product>
    <os:product>
        <os:productId>2</os:productId>
        <os:name>Achtung Baby - U2</os:name>
        <os:description>Audio CD</os:description>
        <os:price>21.0</os:price>
        <os:campaignPrice>19.0</os:campaignPrice>
        <os:icon>images/u2AchtungBaby.jpg</os:icon>
    </os:product>
    <os:product>
        <os:productId>4</os:productId>
        <os:name>Achtung Baby - U2</os:name>
        <os:description>Audio CD</os:description>
        <os:price>21.0</os:price>
        <os:campaignPrice>19.0</os:campaignPrice>
        <os:icon>images/u2AchtungBaby.jpg</os:icon>
    </os:product>
  </os:catalog>
  <os:membership>
    <os:customer>
        <os:userId>eteration</os:userId>
        <os:name>Esma Meral</os:name>
        <os:address>ITU andesea</os:address>
        <os:phone>+90 123 456 789</os:phone>
        <os:email>a@b.com</os:email>
    </os:customer>
  </os:membership>
</os:objectshop>

【问题讨论】:

    标签: xml xsd xls


    【解决方案1】:

    您的 XSD 文件应该具有如下格式的 XML 文件

    <os:objectshop>
      <os:CatalogType>
        ...
      </os:CatalogType>
      <os:MembersType>
        ...
      </os:MembersType>
    </os:objectshop>
    

    例如定义在

     <complexType name="ObjectShopType">
      <sequence>
        <element name="CatalogType" type="os:CatalogType"></element>
        <element name="MembersType" type="os:MembersType"></element>
      </sequence>
    </complexType>
    

    我建议更新您的架构以替换

    <complexType name="CatalogType">
        <sequence>
          <element name="ProductType" type="os:ProductType" minOccurs="0" maxOccurs="unbounded"/>
        </sequence>
      </complexType>
      <complexType name="ObjectShopType">
        <sequence>
          <element name="CatalogType" type="os:CatalogType"/>
          <element name="MembersType" type="os:MembersType"/>
        </sequence>
      </complexType>
    

    <complexType name="CatalogType">
        <sequence>
          <element name="product" type="os:ProductType" minOccurs="0" maxOccurs="unbounded"/>
        </sequence>
      </complexType>
      <complexType name="ObjectShopType">
        <sequence>
          <element name="catalog" type="os:CatalogType"/>
          <element name="membership" type="os:MembersType"/>
        </sequence>
      </complexType>
    

    【讨论】:

    • 非常感谢!我做了设计视图,它做到了!
    猜你喜欢
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 2021-01-20
    • 2018-10-24
    • 2018-06-22
    相关资源
    最近更新 更多