Sign In/My Account | View Cart  
advertisement

Article:
 Architectural Design Patterns for XML Documents
Subject: Elements with only sub-elements
Date: 2003-06-06 07:19:16
From: Andres Becerra
Response to: Elements with only sub-elements

I came to a solution based on posts by different people. I wanted to share the solution in case anyone ran into this problem in the future. Below is the XSD I ended up using:



<xs:element name="Content">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="0" />
</xs:sequence>
<xs:attribute name="ContentHeight" type="xs:string" />
</xs:complexType>
</xs:element>



Another option I had was to tightly validate exactly what valid elements are allowed in <Content> elements, using this XSD schema snippet:


<xs:element name="Content">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:all>
<xs:element ref="label" minOccurs="0" />
<xs:element ref="TableView" minOccurs="0" />
</xs:all>
<xs:attribute name="ContentHeight" type="xs:string" />
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>



I ended up going with the 1st option simply because it was more flexible over the long run. In the near future, there may be transformers written for new elements that can be placed in the <Content> element, so I didn't want to restrict it too much.... just as long as no plain text was allowed in the <Content> element, only sub-elements.


Cheers,
Andres


No Previous Message Previous Message Move up to Parent Message Up Next Message No Next Message


Sponsored By: