Newbie question: Attributes and schema's

R

Robert Dunn

Hi,

I'm interested in creating a schema that enforces a node tree based on
an attribute. For example:

<Invocation type="COM">
<GUID>{63D94CD7-C566-457D-B011-D544483D7862}</GUID>
</Invocation>
<Invocation type="DCOM">
<MachineName>IITWEB-1</MachineName>
<GUID>{63D94CD7-C566-457D-B011-D544483D7862}</GUID>
</Invocation>
<Invocation type="DLL">
<Location>C:\Temp\Product.dll</Location>
</Invocation>

Is this possible? At the moment I've got the schema with a choice
around MachineName, GUID and Location but ultimately it would be nice
to enforce the relationship between the nodes and the attribute.
Current schema:

<xs:element name="Invocation">
<xs:complexType>
<xs:choice>
<xs:element ref="MachineName" minOccurs="0"/>
<xs:element ref="GUID" minOccurs="0"/>
<xs:element ref="Location" minOccurs="0"/>
</xs:choice>
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="COM"/>
<xs:enumeration value="DCOM"/>
<xs:enumeration value="DLL"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>

Thanks,
Rob.
 
M

Martin Honnen

Robert Dunn wrote:

I'm interested in creating a schema that enforces a node tree based on
an attribute. For example:

<Invocation type="COM">
<GUID>{63D94CD7-C566-457D-B011-D544483D7862}</GUID>
</Invocation>
<Invocation type="DCOM">
<MachineName>IITWEB-1</MachineName>
<GUID>{63D94CD7-C566-457D-B011-D544483D7862}</GUID>
</Invocation>
<Invocation type="DLL">
<Location>C:\Temp\Product.dll</Location>
</Invocation>

Is this possible? At the moment I've got the schema with a choice
around MachineName, GUID and Location but ultimately it would be nice
to enforce the relationship between the nodes and the attribute.

There is no way with a W3C XML schema to enforce an element's content
depending on an attribute's value.

There are other schema languages like Schematron for instance which
allow yo to make assertions using the full power of XPath and that way
you are able to check that for a certain attribute value you have a
certain element substructure.
You can find more about Schematron here:
http://xml.ascc.net/schematron/
 
R

Robert Dunn

Martin Honnen said:
Robert Dunn wrote:



There is no way with a W3C XML schema to enforce an element's content
depending on an attribute's value.

There are other schema languages like Schematron for instance which
allow yo to make assertions using the full power of XPath and that way
you are able to check that for a certain attribute value you have a
certain element substructure.
You can find more about Schematron here:
http://xml.ascc.net/schematron/

Martin, thanks for your response.

Rob.
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top