xml - Limit number of occurences of an element based on an attribute value -


i have xml looks this:

<artifacts count="2">   <artifact>     ...   </artifact>   <artifact>     ...   </artifact>  </artifacts> 

i looking way enforce number of artifact elements contained in artifacts shall equal value of "count" attribute using xsd schema.

even though found possible ways achieve using xsd 1.1 specification, wonder if @ possible without it, i.e based on xsd 1.0 specification.


edit: try provide little more context question in order more precise.
xml file provided input c++ application. problem development environment enforces usage of xerces v. 2.8.0 library parsing. understanding version not support xsd 1.1 standard.

of course, can add code in order check correct number of occurrences of artifact elements after xsd validation. hoping there way avoid code segment , validate input file based on xsd alone.

the correct term kind of constraint you'd model assertion. no, assertions not possible in xml schema 1.0. validation languages support assertions xml schema 1.1 (xs:assert) , schematron (sch:assert , sch:report).

other that, write xpath expressions or xslt stylesheets test correct number of artifact elements:

/artifacts/@count = count(/artifacts/artifact) 

the xml file provided input c++ application. problem development environment enforces usage of xerces v. 2.8.0 library parsing. understanding version not support xsd 1.1 standard.

my guess xerces 2.8.0 (an outdated version no longer supported) not conform xsd 1.1, easiest way find out test it. include xs:assert in schema , see happens.

of course, can add code in order check correct number of occurrences of "artifact" elements after xsd validation. hoping there way avoid code segment , validate input file based on xsd alone.

no, xsd 1.0 cannot avoid lines of code.


edit @kjhughes wrote in comment should part of answer:

this correct, , challenge op's design requires attribute merely mirrors number of child attributes.

from point of view of xml design, if attribute nothing else state how many artifact elements there are, why did include in first place? should reluctant store redundant , recoverable information. instance, there no need store position of child elements so:

<root>   <child n="1"/>   <child n="2"/> </root> 

and count attribute similar.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -