473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Xml Schema: Extending base root element with unique/key/keyref element.

I know that the selector of these elements has a scope relative to the element being declared, but maybe there is a way to get beyond bounds of this scope or maybe just a way to extend base element?
Here’s a working example:
Expand|Select|Wrap|Line Numbers
  1. <xs:schema id="schema"
  2.     targetNamespace="http://tempuri.org/schema.xsd"
  3.     elementFormDefault="qualified"
  4.     xmlns="http://tempuri.org/schema.xsd"
  5.     xmlns:mstns="http://tempuri.org/schema.xsd"
  6.     xmlns:xs="http://www.w3.org/2001/XMLSchema">
  7.  
  8.     <xs:element name="element" abstract="true" type="TElement"/>
  9.     <xs:element name="local" type="TLocal" substitutionGroup="element"/>
  10.  
  11.     <xs:element name="root" type="TRoot">
  12.         <!--declaring constraint within TRoot (root element of any document)-->
  13.         <xs:unique name="local-name-constraint">
  14.             <xs:selector xpath=".//mstns:local"/>
  15.             <xs:field xpath="@name"/>
  16.         </xs:unique>
  17.     </xs:element>
  18.  
  19.     <xs:complexType name="TElement" abstract="true">
  20.     </xs:complexType>
  21.  
  22.     <xs:complexType name="TRoot">
  23.         <xs:complexContent>
  24.             <xs:extension base="TElement">
  25.                 <xs:sequence>
  26.                     <xs:element ref="element" maxOccurs="unbounded"/>
  27.                 </xs:sequence>
  28.             </xs:extension>
  29.         </xs:complexContent>
  30.     </xs:complexType>
  31.  
  32.     <xs:complexType name="TLocal">
  33.         <xs:complexContent>
  34.             <xs:extension base="TElement">
  35.                 <xs:sequence>
  36.                     <xs:element ref="element" minOccurs="0" maxOccurs="unbounded"/>
  37.                 </xs:sequence>
  38.                 <xs:attribute name="name" use="required" type="xs:string"/>
  39.             </xs:extension>
  40.         </xs:complexContent>
  41.     </xs:complexType>
  42. </xs:schema>
…and XML document
Expand|Select|Wrap|Line Numbers
  1. <root xmlns="http://tempuri.org/schema.xsd">
  2.     <local name="a"/>
  3.     <local name="b">
  4.         <local name="a"/>
  5.     </local>
  6. </root>
It works and I’ve got notified that there is a duplicate key sequence. But what if I have an extension to this schema where I declared another element:
Expand|Select|Wrap|Line Numbers
  1. <root xmlns="http://tempuri.org/schema.xsd"
  2.       xmlns:e="http://tempuri.org/ext.xsd">
  3.     <local name="one">
  4.         <e:extended key="next"/>
  5.     </local>
  6.     <local name="two">
  7.         <local name="one"/>
  8.         <e:extended key="next"/>
  9.     </local>
  10. </root>
Expand|Select|Wrap|Line Numbers
  1. <xs:schema id="ext"
  2.     targetNamespace="http://tempuri.org/ext.xsd"
  3.     elementFormDefault="qualified"
  4.     xmlns="http://tempuri.org/ext.xsd"
  5.     xmlns:mstns="http://tempuri.org/ext.xsd"
  6.     xmlns:xs="http://www.w3.org/2001/XMLSchema"
  7.     xmlns:base="http://tempuri.org/schema.xsd"
  8. >
  9.  
  10.     <xs:import namespace="http://tempuri.org/schema.xsd"
  11.                schemaLocation="schema.xsd"/>
  12.  
  13.     <xs:element name="extended" type="TExtended" substitutionGroup="base:element">
  14.         <xs:unique name="extended-key-constraint">
  15.             <xs:selector xpath="I can't get to the root of the document here"/>
  16.             <xs:field xpath="@key"/>
  17.         </xs:unique>
  18.     </xs:element>
  19.  
  20.     <xs:complexType name="TExtended">
  21.         <xs:complexContent>
  22.             <xs:extension base="base:TElement">
  23.                 <xs:sequence>
  24.                     <xs:element ref="base:element" minOccurs="0" maxOccurs="unbounded"/>
  25.                 </xs:sequence>
  26.                 <xs:attribute name="key" use="required" type="xs:string"/>
  27.             </xs:extension>
  28.         </xs:complexContent>
  29.     </xs:complexType>
  30.  
  31. </xs:schema>
How can I set uniqueness to the element from the schema extensions?
Aug 4 '09 #1
0 2788

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Olaf Meyer | last post by:
I'm wondering if I can also express uniquness constraints on attributes of objects that I have referenced from somewhere else. To be a bit more precise here a short and simple XML document. The...
1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
0
by: peterpeter | last post by:
Hi. There is a XML schema problem that I have with key/keyref: I have two complex (A and B) types which both inherit from a common base typ (Base). A refers B using a xs:IDREF element named...
2
by: John Carron | last post by:
Hi All, I have written a simple schema (see below) that uses substitution groups. I don't know if this the correct usage because I'm fairly new to xml schema. The structure is as follows: ...
0
by: John Carron | last post by:
Hi All, I have written a simple schema (see below) that uses substitution groups. I don't know if this the correct usage because I'm fairly new to xml schema. The structure is as follows: ...
0
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"...
2
by: svestin | last post by:
Hi All! I run into a problem defining a XSD schema with KEYREF references. Is it possible to use KEYREF with nillable fields? Just like a database where a FK could be null. In the example...
2
by: bmichel | last post by:
Regarding the XSD schema shown below, I want to modifiy it so that: - the "owner_id" attribute in the "dog" element to exist in one of the "owner" element "id" attribute. - the "id" attribute in...
1
by: brucepickford001 | last post by:
Hi, I have a not simple problem. I want the following XML to be schema valid <PopulationDemographic> <PersonName>Joe Blogs</PersonName> <Age>2</Age> <Category>baby</Category>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.