Repository navigation
xs:choice is causing xsd assert error #16
Copy link
Copy link
Open
Description
Am trying to validate my xml with xsd using XML4JS and xsd has "xs:choice".
When i use choice for the element with Type of reference it is failing with below error.
AssertionError [ERR_ASSERTION]: { 'xsd:choice':
[ { 'xsd:annotation':
[ { 'xsd:documentation':
[ '\n Purchase\n order schema.\n ' ] } ],
'xsd:choice':
[ { '$': { minOccurs: '1', maxOccurs: '1' },
'xsd:element':
[ { '$': { name: 'purchaseOrder', type: 'PurchaseOrderType' } } ] } ],
'xs:any':
[ { '$': { namespace: '##other', processContents: 'lax' } } ] } ] }
at assert (/Users/test-user/workspace/poc/xmltojson/node/node_modules/xml4js/lib/assert.js:10:5)
at /Users/test-user/workspace/poc/xmltojson/node/node_modules/xml4js/lib/xsd.js:584:9
at parseNamespacePrefixes (/Users/test-user/workspace/poc/xmltojson/node/node_modules/xml4js/lib/xsd.js:502:3)
at /Users/test-user/workspace/poc/xmltojson/node/node_modules/xml4js/lib/xsd.js:548:7
at Parser.<anonymous> (/Users/test-user/workspace/poc/xmltojson/node/node_modules/xml4js/node_modules/xml2js/lib/xml2js.js:492:18)
at Parser.emit (events.js:198:13)
at SAXParser.onclosetag (/Users/test-user/workspace/poc/xmltojson/node/node_modules/xml4js/node_modules/xml2js/lib/xml2js.js:453:26)
at emit (/Users/test-user/workspace/poc/xmltojson/node/node_modules/sax/lib/sax.js:624:35)
at emitNode (/Users/test-user/workspace/poc/xmltojson/node/node_modules/sax/lib/sax.js:629:5)
at closeTag (/Users/test-user/workspace/poc/xmltojson/node/node_modules/sax/lib/sax.js:889:7)
<?xml version=\"1.0\"?><purchaseOrder orderDate=\"1999-10-20\" validDate=\"1999-10-20\" xmlns=\"http://www.example.com/PO\"><shipTo country=\"US\"><name>Alice Smith</name><street>123 Maple Street</street><city>Mill Valley</city><state>CA</state><zip>90952</zip></shipTo><billTo country=\"US\"><name>Robert Smith</name><street>8 Oak Avenue</street><city>Old Town</city><state>PA</state><zip>95819</zip></billTo><comment>Hurry, my lawn is going wild!</comment><items><item partNum=\"872-AA\"><productName>Lawnmower</productName><quantity>1</quantity><USPrice>148.95</USPrice><comment>Confirm this is electric</comment></item><item partNum=\"926-AA\"><productName>Baby Monitor</productName><quantity>1</quantity><USPrice>39.98</USPrice><shipDate>1999-05-21</shipDate></item></items></purchaseOrder>
XSD :
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.com/PO" targetNamespace="http://www.example.com/PO">
<xsd:element name='comment' type='xsd:string'/>
<xsd:choice>
<xsd:annotation>
<xsd:documentation>
Purchase
order schema.
</xsd:documentation>
</xsd:annotation>
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:element name="purchaseOrder" type="PurchaseOrderType"/>
</xsd:choice>
<xsd:any namespace="##other" processContents="lax" />
</xsd:choice>
<xsd:complexType name='USAddress'>
<xsd:annotation>
<xsd:documentation>
Purchase order schema for Example.Microsoft.com.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name='name' type='xsd:string'/>
<xsd:element name='street' type='xsd:string'/>
<xsd:element name='city' type='xsd:string'/>
<xsd:element name='state' type='xsd:string'/>
<xsd:element name='zip' type='xsd:decimal'/>
</xsd:sequence>
<xsd:attribute name='country' type='xsd:NMTOKEN' fixed='US'/>
</xsd:complexType>
<xsd:simpleType name='SKU'>
<xsd:restriction base='xsd:string'>
<xsd:pattern value='\d{3}\w{3}'/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name='Items'>
<xsd:sequence>
<xsd:element name='item' minOccurs='0' maxOccurs='unbounded'>
<xsd:complexType>
<xsd:sequence>
<xsd:element name='productName' type='xsd:string'/>
<xsd:element name='quantity'>
<xsd:simpleType>
<xsd:restriction base='xsd:positiveInteger'>
<xsd:minInclusive value='1'/>
<xsd:maxExclusive value='100'/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name='USPrice' type='xsd:decimal'/>
<xsd:element ref='comment'/>
<xsd:element name='shipDate' type='xsd:date' minOccurs='0'/>
</xsd:sequence>
<xsd:attribute name='partNum' type='SKU'/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name='PurchaseOrderType'>
<xsd:sequence>
<xsd:element name='shipTo' type='USAddress'/>
<xsd:element name='billTo' type='USAddress'/>
<xsd:element ref='comment' minOccurs='0'/>
<xsd:element name='items' type='Items'/>
</xsd:sequence>
<xsd:attribute name="validDate" type="xsd:date"/>
<xsd:attribute name='orderDate' type='xsd:date'/>
<xsd:attribute name='confirmDate' type='xsd:date' use='required'/>
</xsd:complexType>
</xsd:schema>
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
mitar commentedon Oct 25, 2021
That assertion just means that particular element is not supported by the library at this place. This can be because it is not according to the spec or it is one of things not supported by the library. Looking at the code, it looks like it expects
choiceto be part of thecomplextTypeand not stand-alone.