Newbie question: Attributes and schema's

Discussion in 'XML' started by Robert Dunn, Aug 18, 2004.

  1. Robert Dunn

    Robert Dunn Guest

    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.
    Robert Dunn, Aug 18, 2004
    #1
    1. Advertising

  2. 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/

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Aug 18, 2004
    #2
    1. Advertising

  3. Robert Dunn

    Robert Dunn Guest

    Martin Honnen <> wrote in message news:<41234977$0$28853$-online.net>...
    > 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.
    Robert Dunn, Aug 18, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page