XMLSchema pattern based on attribute

patrik.nyman

Usenet Archive
Joined
Dec 13, 2006
Messages
27
Reaction score
0
I'm wondering if this can be done within an XMLSchema:

I want to define an element <identifier> as having an attribute "type" with one of a given list of values. Based on what value is chosen, I want the *content* of the element to be restricted to following a certain pattern or being of a certain type.

For example, <identifier type="uri"> must contain something on the pattern "[a-z:]+[\d-]", while the content of <foo type="isbn"> must follow the pattern "[\d-]+".

The code I have is

<xs:element name="identifier">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="kb:att.identifier.type"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element>

<xs:attributeGroup name="att.identifier.type">
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="issn"/>
<xs:enumeration value="isbn"/>
<xs:enumeration value="uri"/>
<xs:enumeration value="internal"/>
<xs:enumeration value="iso639-1"/>
<xs:enumeration value="iso639-2"/>
<xs:enumeration value="iso3166-1"/>
<xs:enumeration value="pmid"/>
<xs:enumeration value="keyTitle"/>
<xs:enumeration value="patentNumber"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
 

Pavel Lepin

Usenet Archive
Joined
Apr 20, 2007
Messages
263
Reaction score
0
wrote in
I'm wondering if this can be done within an XMLSchema:

This is funny. I know very little of XML Schemata, because I normally don't use those in my work, but I have a strong feeling that the answer is 'no', because...
I want to define an element <identifier> as having an
attribute "type" with one of a given list of values.
Based on what value is chosen, I want the *content* of the element to be restricted to following a certain pattern or being of a certain type.

For example, <identifier type="uri"> must contain
something on the pattern
"[a-z:]+[\d-]", while the content of <foo type="isbn">
must follow the pattern "[\d-]+".

....this question has been answered on this group no less than *twice* in the last ten days:

<http://groups.google.com/group/comp.text.xml/msg/f230e4846613e07f> <http://groups.google.com/group/comp.text.xml/msg/c1d229fef79a927b>

Google is your friend.
 

Joseph Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
733
Reaction score
0
I want to define an element <identifier> as having an attribute "type" with one of a given list of values. Based on what value is chosen, I want the *content* of the element to be restricted to following a certain pattern or being of a certain type.

The closest you can come to that in XML Schema is to use xsl:type to explicitly select among several types derived from a common type. Schema won't let you make that decision implicitly based on other document content.
 

patrik.nyman

Usenet Archive
Joined
Dec 13, 2006
Messages
27
Reaction score
0
The closest you can come to that in XML Schema is to use xsl:type to explicitly select among several types derived from a common type. Schema won't let you make that decision implicitly based on other document content.

Thanks for that clarification. I actually read your post from a few days ago when you explained this, but then I forgot about it until reminded by Pavel. I wish memory too was my friend. :)

Patrik Nyman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top