XSD错误:不期望XML元素

时间:2016-08-09 13:54:35

标签: xml xsd

请阅读此处的其他问题,但无法弄清楚为何以下XML对http://www.stormware.cz/schema/version_2/data.xsd无效

我应该如何在XML中添加多个元素。 schemaValidate()响应:

  

DOMDocument :: schemaValidate():元素   '{http://www.stormware.cz/schema/version_2/stock.xsd} stockHeader':   不期望这个元素。预计是其中之一(   {http://www.stormware.cz/schema/version_2/stock.xsd} stockDetail,   {http://www.stormware.cz/schema/version_2/stock.xsd} stockAttach,   {http://www.stormware.cz/schema/version_2/stock.xsd} stockSerialNumber,   {http://www.stormware.cz/schema/version_2/stock.xsd} stockPriceItem,   {http://www.stormware.cz/schema/version_2/stock.xsd}打印)。

XML

<?xml version="1.0" encoding="Windows-1250"?>
<dat:dataPack xmlns:dat="http://www.stormware.cz/schema/version_2/data.xsd"
xmlns:stk="http://www.stormware.cz/schema/version_2/stock.xsd"
xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd"
id="Sklad" ico="02021123"
application="Eshop" version="2.0" note="Import zasob.">
    <dat:dataPackItem id="ZAS20160809" version="2.0">
        <stk:stock version="2.0">

                <stk:stockHeader>
                    <stk:stockType>card</stk:stockType>
                    <stk:code>C Set-G/Fe-K</stk:code>
                </stk:stockHeader>
                <stk:stockHeader>
                    <stk:stockType>card</stk:stockType>
                    <stk:code>C Set-G/Zn-K</stk:code>
                </stk:stockHeader>
        </stk:stock>
    </dat:dataPackItem>
</dat:dataPack>

非常感谢你的帮助。

2 个答案:

答案 0 :(得分:1)

stockHeader 在stock.xsd中声明如下:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<ul id="mobileNav">
     <li class="toggle"><a href="#canvas" id="mobile-close-nav" class="icon-close"></a></li>
     <li class="folder">
           <input type="checkbox" name="mobile-folder-toggle" id="mobile-folder-toggle1" class="folder-toggle-box hidden">
           <label for="mobile-folder-toggle1" class="folder-toggle-label" data-href="#">About</label>
           <div class="subnav">
                <ul class="sub-menu">
                    <li class="page-collection"><a href="#">About Us</a></li>
                    <li class="page-collection"><a href="#">The Team</a></li>
                </ul>
           </div>
     </li>
     <li class="folder">
           <input type="checkbox" name="mobile-folder-toggle" id="mobile-folder-toggle2" class="folder-toggle-box hidden">
           <label for="mobile-folder-toggle2" class="folder-toggle-label" data-href="#">Products</label>
           <div class="subnav">
                <ul class="sub-menu">
                    <li class="page-collection"><a href="#">First</a></li>
                    <li class="page-collection"><a href="#">Second</a></li>
                    <li class="page-collection"><a href="#">Third</a></li>
                </ul>
           </div>
      </li>
</ul>

缺少maxOccurs默认值为1,因此stockHeader可能出现0或1次。

要允许更多,应将其更改为

<xsd:element
  name="stockHeader"
  type="stk:stockHeaderType"
  minOccurs="0"/>

答案 1 :(得分:1)

我猜您正在尝试添加多个库存更新。正如Ghislain Fourny所说,

  

<stk:stockHeader>

只能出现一个。

对于多个股票更新,请使用

  

<dat:dataPackItem >

例如:

<dat:dataPackItem id="ZAS001" version="2.0">
  <stk:stock version="2.0">
    <stk:actionType>
      <stk:add/>
    </stk:actionType>
    <stk:stockHeader>
    ...
    ...
    </stk:stockHeader>    
  </stk:stock>
</dat:dataPackItem>
<dat:dataPackItem id="ZAS002" version="2.0">
  <stk:stock version="2.0">
    <stk:actionType>
      <stk:add/>
    </stk:actionType>
    <stk:stockHeader>
    ...
    ...
    </stk:stockHeader>    
  </stk:stock>
</dat:dataPackItem>