Connecting Tech Pros Worldwide Help | Site Map

Restrictions For Elements With The Same Names

  #1  
Old September 29th, 2008, 01:05 AM
jamil@onepost.net
Guest
 
Posts: n/a
Take a look at the following XML doc:

<main>
<a>
<element>123</element>
</a>
<b>
<element>abc</element>
</b>
<c>
<element>true</element>
</c>
</main>

With this document, is it possible to create an XSD schema with
restrictions for the element "element" depending on its ancestor?

/main/a/element must be an integer containing only three digits.
/main/b/element must be a string containing only three characters.
/main/c/element must be a boolean.

I can define this in a schema if the elements had different names, but
I do not see a way to do it with the same name of element.

Thanks.
  #2  
Old September 29th, 2008, 12:05 PM
Martin Honnen
Guest
 
Posts: n/a

re: Restrictions For Elements With The Same Names


jamil@onepost.net wrote:
Quote:
Take a look at the following XML doc:
>
<main>
<a>
<element>123</element>
</a>
<b>
<element>abc</element>
</b>
<c>
<element>true</element>
</c>
</main>
>
With this document, is it possible to create an XSD schema with
restrictions for the element "element" depending on its ancestor?
>
/main/a/element must be an integer containing only three digits.
/main/b/element must be a string containing only three characters.
/main/c/element must be a boolean.
>
I can define this in a schema if the elements had different names, but
I do not see a way to do it with the same name of element.
As those 'element' elements are children of different elements (e.g.
'a', 'b', 'c') it should not be a problem:

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="main">
<xs:complexType>
<xs:sequence>
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element name="element">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:totalDigits value="3"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="b">
<xs:complexType>
<xs:sequence>
<xs:element name="element">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="3"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="c">
<xs:complexType>
<xs:sequence>
<xs:element name="element" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

--

Martin Honnen
http://JavaScript.FAQTs.com/
  #3  
Old September 29th, 2008, 05:05 PM
jamil@onepost.net
Guest
 
Posts: n/a

re: Restrictions For Elements With The Same Names


On Mon, 29 Sep 2008 12:59:28 +0200, Martin Honnen <mahotrash@yahoo.de>
wrote:
Quote:
>As those 'element' elements are children of different elements (e.g.
>'a', 'b', 'c') it should not be a problem:
An example of doing this was very helpful. Thank you.

My problem was that I was attempting to do this with a globally named
type, which wasn't working due to all elements sharing the same name.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Welcome to 'ciwas',this is our FAQ for stylesheet authors v1.16 Jan Roland Eriksson answers 0 July 21st, 2005 01:11 AM
javascript and form names dan answers 10 July 20th, 2005 01:01 PM
Naming rules for JavaScript/HTML scripting VK answers 4 July 20th, 2005 11:55 AM
python-dev Summary for 2004-08-01 through 2004-08-15 Brett Cannon answers 17 July 18th, 2005 03:27 PM