xs:key effective across xi:includes?

Discussion in 'XML' started by daldridge@gmail.com, Apr 18, 2007.

  1. Guest

    I don't know if what I want to do is possible or not, but I'd like to
    have an xs:key in my schema that constrains attributes directly in a
    document, as well as those in another document, included in the
    first. Here's an example of what I'm trying to say:

    FooList.xsd:
    ================
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xi="http://www.w3.org/2001/XInclude"
    xmlns:FooList="http://www.somecompany.com/FooList"
    targetNamespace="http://www.somecompany.com/FooList"
    xmlns="http://www.trionworld.com" elementFormDefault="qualified">

    <xs:import namespace="http://www.w3.org/2001/XInclude"
    schemaLocation="http://www.w3.org/2001/XInclude.xsd"/>

    <!-- Range-limited data type for 'Bar' attributes on 'Foo's. An
    xs:key will
    constrain the value to be unique (can you extend/restrict xs:ID to
    specify
    both min and max? ...). -->
    <xs:simpleType name="BarAttr">
    <xs:restriction base="xs:nonNegativeInteger">
    <xs:minExclusive value="0"/>
    <xs:maxInclusive value="65535"/>
    </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="Foo">
    <xs:attribute name="Bar" type="FooList:BarAttr" use="required"/>
    </xs:complexType>

    <xs:element name="FooList">
    <xs:complexType>
    <xs:sequence minOccurs="0">
    <xs:element ref="xi:include" minOccurs="0"
    maxOccurs="unbounded"/>
    <xs:element name="Foo" type="FooList:Foo" minOccurs="0"
    maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:key name="PK_FooBar">
    <xs:selector xpath="FooList:Foo"/>
    <xs:field xpath="@Bar"/>
    </xs:key>
    </xs:element>

    </xs:schema>


    FooListA.xml
    ==========
    <?xml version="1.0" encoding="UTF-8"?>
    <FooList xmlns="http://www.somecompany.com/FooList"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.somecompany.com/FooList FooList.xsd">

    <Foo Bar="1"/>
    <Foo Bar="2"/>

    </FooList>


    FooListB.xml
    ==========
    <?xml version="1.0" encoding="UTF-8"?>
    <FooList xmlns="http://www.somecompany.com/FooList"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.somecompany.com/FooList FooList.xsd">

    <include xmlns="http://www.w3.org/2001/XInclude" href="FooListA.xml"
    xpointer="FooList:FooList"/>

    <Foo Bar="1"/>
    <Foo Bar="2"/>

    </FooList>


    Essentially, I would like validation of FooListB.xml to fail, given
    that it has 'Bar' attribute values which conflict with those in
    FooListA.xml (assuming my include directive is correct...?). I'm
    basically trying to "merge" document fragments into a master document,
    and have the key constraint be useful.

    Is this possible?

    Cheers,
    -David
     
    , Apr 18, 2007
    #1
    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.
Similar Threads
  1. Joe Buick

    Effective Email Marketing

    Joe Buick, Nov 29, 2004, in forum: VHDL
    Replies:
    0
    Views:
    482
    Joe Buick
    Nov 29, 2004
  2. Andrew FPGA
    Replies:
    14
    Views:
    1,185
    Jim Lewis
    Oct 5, 2005
  3. Mazen
    Replies:
    0
    Views:
    387
    Mazen
    Jul 11, 2003
  4. Yan-Hong Huang[MSFT]
    Replies:
    0
    Views:
    437
    Yan-Hong Huang[MSFT]
    Oct 15, 2003
  5. M P
    Replies:
    1
    Views:
    551
Loading...

Share This Page