xml - Restricting an element to having text, or subelements -
We have a situation where we want to ban an element:
- Either text (). Or
- Subelements.
For example.
& lt; A & gt; Mytext & lt; / A & gt;
or
but not:
& lt; A & gt; Mytext & lt; B & gt; Xxx & lt; / B & gt; & Lt; / A & gt; Looking at the system, I can restrict it to just keep the text, and of course I can define the element (elements), it can be allowed, but nobody knows how I combine the two Can I? Allow any text or sub-committees, but not both? Ta Jamie
Another option is to use heritage Your resulting XML is not very beautiful, but you get the content you want:
& lt; Xsd: element name = "field" type = "field" abstract = "true" /> & Lt; Xsd: element name = "subfield" type = "xsd: string" /> & Lt; Xsd: complex type name = "field" abstract = "true" /> & Lt; Xsd: complex type name = "subfield" & gt; & Lt; XSD: complexContent & gt; & Lt; Xsd: extension base = "field" & gt; & Lt; XSD: Sequence & gt; & Lt; Xsd: element ref = "subfield" minOccurs = "0" maxOccurs = "unbounded" /> & Lt; / XSD: Sequence & gt; & Lt; Xsd: attribute name = "name" type = "xsd: string" /> & Lt; / XSD: Expansion & gt; & Lt; / XSD: complexContent & gt; & Lt; / XSD: complexType & gt; & Lt; Xsd: complex type name = "no-subfield" & gt; & Lt; Xsd: complex content mixed = "true" & gt; & Lt; Xsd: extension base = "field" & gt; & Lt; Xsd: attribute name = "name" type = "xsd: string" /> & Lt; / XSD: Expansion & gt; & Lt; / XSD: complexContent & gt; & Lt; / XSD: complexType & gt;
Then your resulting XML will contain the following (assuming you have xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
has been declared somewhere)
& lt; Area xsi: type = "subfield" & gt; & Lt; Subfold & gt; Your stuff here & lt; / Subfield & gt; & Lt; / Region & gt;
or
& lt; Field xsi: type = "no-subfield" & gt; Your other stuff & lt; / Field & gt;
Most importantly, it denies
Comments
Post a Comment