 |
 |
 |
I'm afraid XSD doesn't allow you to do what you want.
You might be able to add schematron constraints to your XSD to allow you to
specify what you want, but I'll have to leave that to others to explain.
Other than that you are left with defining a schema that allows multiple
'field' elements and then enforcing the additional constraints in your
application.
FWIW XSD would allow you to define a schema that allowed instances of:
<root>
<word name="one">
<field>
<field1><number1>any string here</number1></field1>
<field2><number2>any string here</number2></field2>
...
but it sounds like you don't have that option.
HTH,
Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/ for XML C++ data binding
----- Original Message -----
From: "King, Jeffrey (Mission Systems)" <Jeff.King@n...>
To: <xmlschema-dev@w...>
Sent: Friday, January 04, 2008 2:29 PM
Subject: Repeating elements with fixed attribute values
I have an xml document similar to this:
<root>
<word name="one">
<field name="field1" number="1">any string here</field>
<field name="field2" number="2">any string here</field>
<field name="field3" number="3">any string here</field>
...
</word>
<word name="two">
<field name="field4" number="4">any string here</field>
<field name="field5" number="5">any string here</field>
<field name="field6" number="6">any string here</field>
...
</word>
</root>
The attributes have fixed values. I am struggling to create a schema
for this.
If I take this approach:
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="1" minOccurs="1" name="word">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="1" minOccurs="1" name="field">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string"
use="required" fixed="field1" />
<xs:attribute name="number"
type="xs:unsignedShort" use="required" fixed="1" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="1" minOccurs="1" name="field">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string"
use="required" fixed="field2" />
<xs:attribute name="number"
type="xs:unsignedShort" use="required" fixed="2" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
...
etc.
I get an error stating: "Elements with the same name and in the same
scope must have the same type". I'm not sure what approach to take
here. I think this is pretty elementary, but any help with finding a
solution would be appreciated.
Thank you.
Jeffrey
From mike@s... Fri Jan 04 15:27:50 2008
Received: from maggie.w3.org ([193.51.208.68])
by frink.w3.org with esmtp (Exim 4.63)
(envelope-f
|
 | 

|  |
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.
|  |
| |
 |
 |
 |