xml - Is it allowed to have multiple elements with same name in XSD? -


i having discussion client whether it's allowed have multiple elements in xsd same name. let me try , explain.

creditinvoice.xsd (contains invoice element inside creditinvoice element)

<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeformdefault="unqualified" elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema">    <xs:element name="creditinvoice">     <xs:complextype>       <xs:sequence>         <xs:element name="invoice" minoccurs="0" maxoccurs="unbounded">           <xs:complextype>             <xs:element name="creditno" type="xs:string" />             <xs:sequence>               <xs:element name="invoicedate" type="xs:date" />               <xs:element name="invoiceno" type="xs:string" />             </xs:sequence>           </xs:complextype>         </xs:element>       </xs:sequence>     </xs:complextype>   </xs:element> </xs:schema> 

invoice.xsd (contains root invoice element)

<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeformdefault="unqualified" elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema">    <xs:element name="invoice">     <xs:complextype>       <xs:sequence>         <xs:element name="invoicedate" type="xs:date" />         <xs:element name="invoiceno" type="xs:string" />         <xs:element name="invoicereceiver" type="xs:string" />         <xs:element name="duedate" type="xs:date" />       </xs:sequence>     </xs:complextype>   </xs:element> </xs:schema> 

main.xsd (main xsd document includes other xsd documents.)

<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeformdefault="unqualified" elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema">    <xs:include schemalocation="creditinvoice.xsd"/>   <xs:include schemalocation="invoice.xsd"/>    <xs:element name="invoices">     <xs:complextype>       <xs:sequence>         <xs:choice minoccurs="0" maxoccurs="unbounded">           <xs:element ref="creditinvoice" />           <xs:element ref="invoice" />         </xs:choice>       </xs:sequence>           </xs:complextype>   </xs:element>  </xs:schema> 

when open main.xsd in example cam template editor (http://www.cameditor.org) element ref invoice in main.xsd uses invoice element defined in creditinvoice.xsd instead of element defined in invoice.xsd client trying achieve.

if change order of include elements include invoice.xsd before creditinvoice.xsd works ok.

the client says it's valid xsd. don't know if is. how should (main.xsd) know invoice element should reference to? see same error using tool.

however if open main.xsd using stylus studio xml professional looks ok.

can tell me behaviour correct?

the client says it's valid xsd. don't know if is.

it's not valid xsd, , not conforming xsd, not reasons you're asking about.

the complex type given local element invoice in creditinvoice.xsd not valid: has xsd:element element child of xsd:complextype. assume typo resulting whatever did cut example down manageable size. if declaration creditno moved xsd:sequence element, schema document becomes valid, , schema defined 3 schema documents give becomes conforming schema.

on question of having local elements same name top-level / global elements, client without question correct. it's legal, it's intended legal, it's important part of design of xsd. (@augusto may right can confusing; designers should careful in use of feature. it's conformant.)

how should (main.xsd) know invoice element should reference to? see same error using tool.

you "same error", haven't described error message. perhaps mean tool seems take <xs:element ref="invoice" /> in main.xsd reference invoice defined in creditinvoice.xsd , not reference invoice defined in invoice.xsd.

any reference element, <xs:element ref="invoice" /> in main.xsd, reference top-level (aka global) element matching name. in conforming schema there @ 1 such element. when schema constructed declarations in various schema documents in example, conforming processor know invoice element can appear child of invoices top-level invoice element declared in invoice.xsd. cannot invoice element declared in creditinvoice.xsd, because element local complex type of creditinvoice element. local element, can used declared , cannot used elsewhere.

if correct in saying tools mention treat element reference in main.xsd reference invoice declared local creditinvoice in creditinvoice.xsd, have identified bug in tools. if care tools , have goodwill vendors, should report issue can fix it.

however if open main.xsd using stylus studio xml professional looks ok.

can tell me behaviour correct?

the spec can tell you; reliable books can tell you; reliable tools can tell (with lot less effort reading in spec).


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -