Trying to define a unique id
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 10
- Joined: Wed Jul 07, 2004 7:45 pm
Trying to define a unique id
I think I want to use xs:key as opposed to xs:unique because xs:key cannot be NULL.
OK, here's my schema fragment:
There are no more than 10 sectors, numbered 1 thru 10.
But the following XML file comes up valid. What did I miss ?
[/code]
OK, here's my schema fragment:
Code: Select all
<xs:complexType name="sectorType">
<xs:sequence>
<xs:element name="id">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="10"/>
</xs:restriction>
</xs:simpleType>
<xs:key name="sec_id">
<xs:selector xpath=".//sectorType"/>
<xs:field xpath="id"/>
</xs:key>
</xs:element>
<xs:element thing1 …/>
<xs:element thing2 …/>
<xs:element thing3 …/>
</xs:sequence>
</xs:complexType>
<xs:element name="sector" type="sectorType" minOccurs="1" maxOccurs="10">
But the following XML file comes up valid. What did I miss ?
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="foo.xsd">
<sector>
<id>1</id>
<thing1>…</thing1>
<thing2>…</thing2>
<thing3>…</thing3>
</sector>
<sector>
<id>2</id>
<thing1>…</thing1>
<thing2>…</thing2>
<thing3>…</thing3>
</sector>
<sector>
<id>1</id>
<thing1>…</thing1>
<thing2>…</thing2>
<thing3>…</thing3>
</sector>
</foo>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Dan,
You should define the foo element to contain sector elements in your schema. Then the place where you should define the key is the foo element declaration so that you will be able to select all the sector elements in the key selector. The following schema should work ok with your document:
Hope that helps,
George
You should define the foo element to contain sector elements in your schema. Then the place where you should define the key is the foo element declaration so that you will be able to select all the sector elements in the key selector. The following schema should work ok with your document:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="sectorType">
<xs:sequence>
<xs:element name="id">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="thing1"/>
<xs:element name="thing2"/>
<xs:element name="thing3"/>
</xs:sequence>
</xs:complexType>
<xs:element name="foo">
<xs:complexType>
<xs:sequence>
<xs:element name="sector" type="sectorType" minOccurs="1" maxOccurs="10"/>
</xs:sequence>
</xs:complexType>
<xs:key name="sec_id">
<xs:selector xpath=".//sector"/>
<xs:field xpath="id"/>
</xs:key>
</xs:element>
</xs:schema>
George
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Just a small note:
taking into account that the sector can appear only as child of the foo element.
Best Regards,
George
can be better written asgeorge wrote:Code: Select all
<xs:key name="sec_id">
<xs:selector xpath=".//sector"/>
<xs:field xpath="id"/>
</xs:key>
Code: Select all
<xs:key name="sec_id">
<xs:selector xpath="sector"/>
<xs:field xpath="id"/>
</xs:key>
Best Regards,
George
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service