Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Xml Schema substitution groups / key and keyref

Reply
Thread Tools

Xml Schema substitution groups / key and keyref

 
 
John Carron
Guest
Posts: n/a
 
      09-01-2005
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"
xmlnssi="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" xmlnss="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>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Schema EDC, UPA and substitution groups Soren Kuula XML 2 02-03-2006 04:20 AM
Xml Schema substitution groups / key keyref John Carron XML 2 09-02-2005 06:22 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
XML schema - key/keyref and inheritance peterpeter XML 0 02-11-2004 01:38 PM
Key/keyref validation in schema? Marek Malowidzki XML 1 08-19-2003 12:13 PM



Advertisments