473,396 Members | 2,039 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,396 software developers and data experts.

Xml Schema substitution groups / key and keyref

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:

Request
Report
TargetReference (reference identifier attribute)
Target (identifier attribute)

Example Document:

<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="urn:demo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:demo
Untitled23.xsd">
<DummyReport identifier="10">
<TargetReference identifier="20"/>
</DummyReport>
<DummyTarget identifier="20"/>
</Request>

A valid document can contain a number of reports and targets. The target
reference element should reference only targets in the document and I would
like to enforce this. Does anybody know how to do this? I was initially
thinking along the lines of using the Key and KeyRef elements but don't know
how to do that with substitution groups? Is it possible? I would also like
to enforce that all target identifier attributes are unique. Can this be
done?

Any help would be appreciated.

Regards

Darren

2) Send newsgroup message:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="urn:demo" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:demo" elementFormDefault="qualified"
attributeFormDefault="unqualified">

<!-- Root element request -->
<xs:element name="Request">
<xs:complexType>
<xs:sequence>
<xs:element ref="ReportGroup"
maxOccurs="unbounded"/>
<xs:element ref="TargetGroup"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<!-- Abstract report type -->
<xs:complexType name="Report" abstract="true">
<xs:sequence>
<xs:element ref="TargetReference"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="identifier" type="xs:int"
use="required"/>
</xs:complexType>

<!-- Abstract target type -->
<xs:complexType name="Target" abstract="true">
<xs:attribute name="identifier" type="xs:int"
use="required"/>
</xs:complexType>
<xs:element name="ReportGroup" type="Report" abstract="true"/>
<xs:element name="TargetGroup" type="Target" abstract="true"/>

<!-- Element to join a report to a target -->
<xs:element name="TargetReference">
<xs:complexType>
<xs:attribute name="identifier" type="xs:int"
use="required"/>
</xs:complexType>
</xs:element>

<!-- Reports -->
<xs:element name="DummyReport" substitutionGroup="ReportGroup">
<xs:complexType>
<xs:complexContent>
<xs:extension base="Report"/>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="AnotherDummyReport"
substitutionGroup="ReportGroup">
<xs:complexType>
<xs:complexContent>
<xs:extension base="Report"/>
</xs:complexContent>
</xs:complexType>
</xs:element>

<!-- Targets -->
<xs:element name="DummyTarget" substitutionGroup="TargetGroup">
<xs:complexType>
<xs:complexContent>
<xs:extension base="Target"/>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="DummyTarget2" substitutionGroup="TargetGroup">
<xs:complexType>
<xs:complexContent>
<xs:extension base="Target"/>
</xs:complexContent>
</xs:complexType>
</xs:element>

</xs:schema>


Sep 1 '05 #1
0 1140

This thread has been closed and replies have been disabled. Please start a new discussion.

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...
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: Victor | last post by:
I have a Schema with some elements which are "types" or objects, and some elements which correspond to instances of the types. How can I specify that a <locationInstance> must have an attribute...
3
by: Rabe | last post by:
Hi all, here a little brain-twister (starting to spoil my weekend if I do not find a solution ... ;-) ) What I want to do is to find a XML-Schema expression that builds a grammar for the...
5
by: Harald Haspl | last post by:
Hello, I've appended a simple XML file and it's appropriate schema below. I want to validate the XML file against the schema with xerces-c. This example contains a section where colours are...
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: 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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.