|
Dit artikel is gepubliceerd op zondag 31 juli 2011 op vbvoorbeelden, bezoek de website voor een recente versie van dit artikel of andere artikels.
Als in volgende XML instantie de combinatie van de <id> elementwaarde en title attribuutwaarde van een <topic> element uniek moet zijn : XML Instantie <?xml version="1.0" encoding="utf-8"?>
<book title="My Book">
<text>My book...</text>
<topic title="Introduction">
<id>01</id>
<text>This is the introduction...</text>
<example>First example...</example>
<text>To finalize....</text>
</topic>
<text>Some other text...</text>
<topic title="Into Details">
<id>02</id>
<text>Another text...</text>
</topic>
</book>Dan kunnen we hiervoor volgend schema opstellen : XML Schema Definition <?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="book">
<xsd:complexType>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="text" type="xsd:string" />
<xsd:element name="topic" type="topicType" />
</xsd:choice>
<xsd:attribute name="title" type="xsd:string" />
</xsd:complexType>
<xsd:unique name="uniqueTopicIDAndTitle">
<xsd:selector xpath="topic" />
<xsd:field xpath="id" />
<xsd:field xpath="@title" />
</xsd:unique>
</xsd:element>
<xsd:complexType name="topicType">
<xsd:sequence>
<xsd:element name="id" type="xsd:string" />
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="text" type="xsd:string" />
<xsd:element name="example" type="xsd:string" />
</xsd:choice>
</xsd:sequence>
<xsd:attribute name="title" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:schema>Het xsd:unique element, die een name moet hebben, geeft in zen xsd:selector childelement aan waarbinnen de uniciteit moet gelden en in zen xsd:field childelementen welke ( combinatie van ) waarde(s) uniek moet(en) zijn.
Zowel xsd:selector als xsd:field maken gebruik van een XPath expressie om aan te geven waarop uniciteit van toepassing is. Voor iets meer informatie over of toepassingen met XPath kan je terecht in het hoofdstuk over XML transformatie. Voor nog meer details kan je terecht op http://www.w3.org/TR/xpath/.
Volgende XML instantie is niet conform dit schema gezien de herhaalde combinatie van title "Introduction" en id "01" : XML Instantie <?xml version="1.0" encoding="utf-8"?>
<book title="My Book">
<text>My book...</text>
<topic title="Introduction">
<id>01</id>
<text>This is the introduction...</text>
<example>First example...</example>
<text>To finalize....</text>
</topic>
<text>Some other text...</text>
<topic title="Into Details">
<id>02</id>
<text>Another text...</text>
</topic>
<topic title="Introduction">
<id>01</id>
</topic>
</book>
Dit artikel is gepubliceerd op zondag 31 juli 2011 op vbvoorbeelden, bezoek de website voor een recente versie van dit artikel of andere artikels.
| hoofdstuk |
28. 29. 30.  |
| onderwerp |
29.17. 29.18. XSD Unieke Waardes 29.19.  |
| broncode |
|
| datum |
laatst gewijzigd op maandag 22 november 2010, laatst gepubliceerd op zondag 31 juli 2011 |
|