[XML-DEV Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Derivation of complex types, depending on attribute - Schema, RelaxNGor
- From: Nils Kaiser <NilsKaiser@g...>
- To: xml-dev@l...
- Date: Tue, 25 Nov 2008 17:38:22 +0100
Hi all,
While developing a schema for the usecase described below, I'm
encountering xml schema limitations. I would appreciate input on how to
best model the xml and the best method to validate it (if possible with
schema or better done with relax NG). Questions are appended below.
Here is a xml snippet which is used to declare content using
templates, lets say (namespaces removed):
<page>
<section xsi:type="section_intro">
<input xsi:type="input_text"
name="title">Welcome</input>
<input xsi:type="input_longtext"
name="body">Hello, welcome to the
main page</input>
</section>
<section xsi:type="section_withpic">
<input xsi:type="input_link
name="picurl">http://.......</input>
<input xsi:type="input_longtext"
name="body">This is a wonderful
picture</input>
</section>
<section xsi:type="section_withpic">
<input xsi:type="input_link"
name="picurl">http://.......</input>
<input xsi:type="input_longtext" name="body">This is
<b>another</b> picture</input>
<input xsi:type="input_radio"
name="position">left</input> <!-- optional, only values
allowed left, right, center -->
</section>
</page>
Now, I'd like to be able to validate the sections, i.e. to get an error
in the 2nd section, where the radio input is missing. XML Schema allows
me to use type derivation nicely to derive the types 'intro' and
'withpic' from the same type 'section'. Unfortunately I cannot declare
that the section of type 'withpic' should contain exactly 3 input
elements, with types 'link', 'longtext' and 'radio', respectively. It
seems to be associated to the fact that I cannot declare multiple
elements with the same name but a different type (similar to
http://lists.xml.org/archives/xml-dev/200201/msg01946.html):
<xs:complexType name="section_withpic">
<xs:complexContent>
<xs:extension base="section">
<xs:sequence>
<!-- <xs:element name="input" type="input"/> is
allowed -->
<xs:element name="input" type="input_link"/>
<xs:element name="input" type="input_longtext"/>
<xs:element name="input"
type="input_radio"/> <!-- does not work, multiple elements with
same name not allowed -->
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
Now, I am looking for alternatives to validate the xml:
1) Is there any way to validate the above xml using Schema, but using
derived types (and not only the general type, as in the comment above?)
2) What does relax NG offer in the described case? Would it support the
described xml (replacing 'xsi:type' with a regular type attribute)?
Would I loose any advantage of Schema like type derivation?
3) I know that I could avoid the issue if I use different element names
for the sections and inputs (section_intro, input_link, ...). As the
xml is used to generate API calls, though it would be good to avoid
that as iterating over all 'input' elements wouldn't be possible (or
dirty, iterating over all elements starting with input_ ...).
Thx for any hints or suggestions!
Nils
|
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|
Stylus Studio has published XML-DEV in RSS and ATOM formats,
enabling users to easily subcribe to the list from their preferred news reader application.
|
Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website.
they were not included by the author in the initial post. To view the content without the Sponsor Links please
click here.
|
|