xml - Is it possible to use XSD to define incrementally specified tree structure? -


let's have element either leaf (containing value) or composite (a usual composite pattern). want model tree instances expected refined other instances example filling composite node new elements. want able decide whether 1 tree instance conforms instance structure. possible model instance xsd , implement conformance xsd conforming other xsds? note there more 2 levels - each structure can serve meta-structure.

appendix: better picture of intent here possible rules.

  • "this composite not extensible (is fixed)."
  • "you can add elements @ end of composite."
  • "this composite contains optional leaf 1 , mandatory leaf 2."
  • "this composite contains arbitrary number of occurrences of composite."

examples:

structure 1: composite     0..1 "abc"     1..n "def"     0..n extensible composite "c1"         1..1 "ghi"     0..1 composite "c2"         1..1 "jkl"  structure 2: composite     1..1 "def"     1..1 "def"     1..1 "def"     1..1 extensible composite "c1"         1..1 "ghi"         1..n "extension"     1..n extensible composite "c1"         1..1 "ghi"  structure 3: composite     0..n "abc" //too many "abc"s     //"def" needed     0..1 composite "c2"         1..1 "jkl"         1..1 "mno" //forbidden extension 

the second structure conforms first one, third 1 not. thought maybe expressed schema validation.

if you're discovering xsd, start crafting bunch of xml files, representative you're trying achieve, feed them all @ same time tool can generate 1 (or more) xsd files (depending if use multiple namespaces or not). once have reasonable base in xsd, tackle manually.

this i've tried based on clarifications.

sample1.xml

<composite>     <abc/>     <def/>     <c1>         <ghi/>     </c1>     <c1>         <ghi/>     </c1>     <c2>         <jkl/>     </c2> </composite> 

sample2.xml

<composite>     <def/>     <def/>     <c1>         <ghi/>         <extension/>     </c1>     <c1>         <ghi/>     </c1>    </composite> 

based on above, original generated xsd is:

<?xml version="1.0" encoding="utf-8"?> <!--xml schema generated qtassistant/xml schema refactoring (xsr) module (http://www.paschidev.com)--> <xs:schema attributeformdefault="unqualified" elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema">   <xs:element name="composite">     <xs:complextype>       <xs:sequence>         <xs:element minoccurs="0" name="abc" type="xs:anytype" />         <xs:element maxoccurs="unbounded" name="def" type="xs:anytype" />         <xs:element maxoccurs="unbounded" name="c1">           <xs:complextype>             <xs:sequence>               <xs:element name="ghi" type="xs:anytype" />               <xs:element minoccurs="0" name="extension" type="xs:anytype" />             </xs:sequence>           </xs:complextype>         </xs:element>         <xs:element minoccurs="0" name="c2">           <xs:complextype>             <xs:sequence>               <xs:element name="jkl" type="xs:anytype" />             </xs:sequence>           </xs:complextype>         </xs:element>       </xs:sequence>     </xs:complextype>   </xs:element> </xs:schema> 

it requires tweaking, since of cardinality scenarios you've described not captured xmls. below updated diagram, easier reconciliation original markup.

enter image description here

it should easier see how xsd seems match you've asked (where cardinality not shown, assume (1..1) - default particles in xsd).

how extensions further defined, maybe through use of other mechanism such wild card elements, or constrained based on base type, activities done based on further requirements. if you're getting more sophisticated scenarios, such having mandatory presence based on other element presence or values (co-constraints), xsd 1.0 may not work...

this should started @ least provide additional details question...


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -