Reputation: 5215
Read the other questions here, but can't figure out why is the following XML not valid against http://www.stormware.cz/schema/version_2/data.xsd
How on earth should I add multiple elements into the XML. The schemaValidate() response:
DOMDocument::schemaValidate(): Element '{http://www.stormware.cz/schema/version_2/stock.xsd}stockHeader': This element is not expected. Expected is one of ( {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}print).
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>
Your help would be really appreciated.
Upvotes: 0
Views: 1939
Reputation: 1100
I guess you are trying to add multiple stock updates. As Ghislain Fourny mentioned,
<stk:stockHeader>
can occure only one.
For multiple stock updates use
<dat:dataPackItem >
For example:
<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>
Upvotes: 1
Reputation: 7279
stockHeader is declared in stock.xsd like so:
<xsd:element
name="stockHeader"
type="stk:stockHeaderType"
minOccurs="0"/>
The absence of maxOccurs defaults to a value of 1, so that there can be either 0 or 1 occurrence of stockHeader.
To allow more, it should be changed to
<xsd:element
name="stockHeader"
type="stk:stockHeaderType"
minOccurs="0"
maxOccurs="unbounded"/>
Upvotes: 1