xsd - How to avoid usage of global elements in XML schema -
I want to create an XML schema which only allows a single root node.
The root node in the structure below, is an element that I want to reuse in different places.
My first method was to create a global element in the schema, but if I do this, then an XML document which is valid only for this schema in the form of a single root tag.
How do I create such global elements which are allowed only to be used as a riflement within my basic framework?
This is what I have to do:
& lt; Root & gt; & Lt; Branch & gt; & Lt; Leaf / & gt; & Lt; / Branch & gt; & Lt; Branch & gt; & Lt; Fork & gt; & Lt; Branch & gt; & Lt; Leaf / & gt; & Lt; / Branch & gt; & Lt; / Leaf & gt; & Lt; / Fork & gt; & Lt; / Root & gt; But this is valid & lt; Leaf / & gt; will be also in the form of root node
XML is always just a root node Represents the hierarchical structure and is bound to its schema. So you can not change the original element with the same schema and are valid.
First of all it should be arranged in such a way:
& lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Root xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: nonspace shadow location = "your- scheme.xsd> gt; & lt; leaf / & gt; Pre> I would suggest a plan like this:
"branch" minOccurs = "0" MaxOccurs = "unbounded" /> & lt; / xs: sequence & gt; & Lt; / xs: Complex type & gt; & lt; x: complex type name = "branch" & gt; & lt; xs: likes & gt; & lt; xs: element Ref = "fork" MinOccurs = "0" maxOccurs = "unbounded" /> & Lt; Xs: ele Ment ref = "leaf" minOccurs = "0" maxOccurs = "unbounded" /> & Lt; / XS: sequence & gt; & Lt; / XS: complexType & gt; & Lt; X: complex type name = "leaf" /> & Lt; Xs: element name = "root" type = "parent" /> & Lt; Xs: element name = "branch" type = "branch" /> & Lt; Xs: element name = "fork" type = "fork" /> & Lt; Xs: element name = "address" type = "address" /> & Lt; / XS: Schema & gt; I hope this will help you.
Comments
Post a Comment