What's wrong with this XSD?

Discussion in 'XML' started by uridor@gmail.com, Aug 21, 2007.

  1. Guest

    Hello,
    I've been trying to make my XSD work, but I'm stuck. I did manage to
    narrow it down to a simple use case, so I'd appreciate it if someone
    could load these and see what's wrong:
    It's basically one XML file and two XSDs, listed below.

    Thanks in advance for any suggestions.
    Uri

    XML FILE
    =======
    <?xml version="1.0" encoding="UTF-8"?>
    <sys:process id="x" xmlns:sys="www.aternity.com/sys"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="www.aternity.com/activity c:\temp\a.xsd"/>

    A.XSD FILE
    =========
    <?xml version="1.0" encoding="UTF-8"?>
    <!--W3C Schema generated by XMLSpy v2007 rel. 3 sp1 (http://
    www.altova.com)-->
    <xs:schema xmlns="www.aternity.com/activity" xmlns:xs="http://
    www.w3.org/2001/XMLSchema" xmlns:http="www.aternity.com/http"
    xmlns:sys="www.aternity.com/sys" xmlns:ui="www.aternity.com/ui"
    targetNamespace="www.aternity.com/activity">
    <xs:import namespace="www.aternity.com/sys" schemaLocation="b.xsd"/>

    <xs:complexType name="CT_Rule">

    <!-- this tag works -->
    <xs:attribute name="id" use="required">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:enumeration value="x"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>

    <!-- this tag doesn't work -->
    <!--xs:attributeGroup ref="gr_reference"/-->
    </xs:complexType>


    <xs:attributeGroup name="gr_reference">
    <xs:attribute ref="id" use="optional"/>
    <!--xs:attribute ref="idtype" use="optional"/-->
    </xs:attributeGroup>

    <xs:attribute name="id">
    <xs:simpleType>
    <xs:restriction base="xs:string"/>
    </xs:simpleType>
    </xs:attribute>

    </xs:schema>

    B.XSD FILE
    =========
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="www.aternity.com/activity" xmlns:sys="www.aternity.com/sys"
    targetNamespace="www.aternity.com/sys">
    <xs:import namespace="www.aternity.com/activity"
    schemaLocation="a.xsd"/>

    <xs:element name="process">
    <xs:complexType>
    <xs:complexContent>
    <xs:extension base="sys:CT_Rule"/>
    </xs:complexContent>
    </xs:complexType>
    </xs:element>

    <xs:complexType name="CT_Rule">
    <xs:complexContent>
    <xs:extension base="CT_Rule"/>
    </xs:complexContent>
    </xs:complexType>
    </xs:schema>
     
    , Aug 21, 2007
    #1
    1. Advertising

  2. Guest

    On 21 Aug, 09:53, wrote:
    > Hello,
    > I've been trying to make my XSD work, but I'm stuck. I did manage to
    > narrow it down to a simple use case, so I'd appreciate it if someone
    > could load these and see what's wrong:
    > It's basically one XML file and two XSDs, listed below.

    ....
    > <?xml version="1.0" encoding="UTF-8"?>
    > <!--W3C Schema generated by XMLSpy v2007 rel. 3 sp1 (http://www.altova.com)-->
    > <xs:schema xmlns="www.aternity.com/activity" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:http="www.aternity.com/http"
    > xmlns:sys="www.aternity.com/sys" xmlns:ui="www.aternity.com/ui"
    > targetNamespace="www.aternity.com/activity">
    > <xs:import namespace="www.aternity.com/sys" schemaLocation="b.xsd"/>
    >
    > <xs:complexType name="CT_Rule">
    >
    > <!-- this tag works -->
    > <xs:attribute name="id" use="required">
    > <xs:simpleType>
    > <xs:restriction base="xs:string">
    > <xs:enumeration value="x"/>
    > </xs:restriction>
    > </xs:simpleType>
    > </xs:attribute>
    >
    > <!-- this tag doesn't work -->
    > <!--xs:attributeGroup ref="gr_reference"/-->
    > </xs:complexType>
    >
    > <xs:attributeGroup name="gr_reference">
    > <xs:attribute ref="id" use="optional"/>
    > <!--xs:attribute ref="idtype" use="optional"/-->
    > </xs:attributeGroup>


    Your definition for CT_Rule contains two attributes called 'id' (one
    directly and one in the attribute group). This is not allowed.

    Also, by convention, your URIs would be http://www.aternity.com/...
    Things won't break if you don't do this, but it is common practice.

    HTH,

    Pete.
    =============================================
    Pete Cordell
    Codalogic
    for XML Schema to C++ data binding visit
    http://www.codalogic.com/lmx/
    =============================================
     
    , Aug 21, 2007
    #2
    1. Advertising

  3. Guest

    On Aug 21, 12:55 pm, wrote:
    > Your definition for CT_Rule contains two attributes called 'id' (one
    > directly and one in the attribute group). This is not allowed.


    Thanks, Pete, but I think you misunderstood: There are two tags there:
    <xs:attributeGroup> and <xs:attribute>, and I only use them one at a
    time (comment the other) - when the <xs:attribute> is used it works,
    but when the <xs:attributeGroup> is used it doesn't work.

    I hope I didn't miss something here.

    the messages I get from XMLSpy are:

    File Untitled4.xml is not valid.
    Attribute 'id' is not allowed in element <sys:process>
    Error location: sys:process / @id
    Details
    cvc-complex-type.3.2.1: Complex type definition '{anonymous}' of
    element <sys:process> does not allow attribute 'id' and no attribute
    wildcard matches it.
    cvc-elt.5.2.1: The element <sys:process> is not valid with respect
    to the actual type definition '{anonymous}'.

    U
     
    , Aug 21, 2007
    #3
  4. Guest

    On 21 Aug, 13:02, wrote:
    > On Aug 21, 12:55 pm, wrote:
    >
    > > Your definition for CT_Rule contains two attributes called 'id' (one
    > > directly and one in the attribute group). This is not allowed.

    >
    > Thanks, Pete, but I think you misunderstood: There are two tags there:
    > <xs:attributeGroup> and <xs:attribute>, and I only use them one at a
    > time (comment the other) - when the <xs:attribute> is used it works,
    > but when the <xs:attributeGroup> is used it doesn't work.
    >
    > I hope I didn't miss something here.
    >
    > the messages I get from XMLSpy are:
    >
    > File Untitled4.xml is not valid.
    > Attribute 'id' is not allowed in element <sys:process>
    > Error location: sys:process / @id
    > Details
    > cvc-complex-type.3.2.1: Complex type definition '{anonymous}' of
    > element <sys:process> does not allow attribute 'id' and no attribute
    > wildcard matches it.
    > cvc-elt.5.2.1: The element <sys:process> is not valid with respect
    > to the actual type definition '{anonymous}'.
    >
    > U


    Ah yes, I did mis-understand you. (I thought you commented it out to
    signal that it doesn't work!)

    However, I think the reason the second one does not work is because
    the attribute group refers to a global attribute for id. Because it
    is a global attribute, it has to have a namespace prefix in an XML
    instance, because the default namespace that works for elements does
    not work for attributes (no namespace prefix for attributes indicates
    it belongs to no namespace as opposed to the default namespace).

    <?xml version="1.0" encoding="UTF-8"?>
    <sys:process activity:id="x" xmlns:sys="www.aternity.com/sys"
    xmlns:activity="www.aternity.com/activity"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="www.aternity.com/activity c:\temp\a.xsd"/>

    HTH,

    Pete.
    =============================================
    Pete Cordell
    Codalogic
    for XML Schema to C++ data binding visit
    http://www.codalogic.com/lmx/
    =============================================
     
    , Aug 21, 2007
    #4
  5. Guest

    Thanks, Pete,
    That fixed it up all right. It is a little annoying, though, to have
    to write the namespace - could some change in the definition of the
    attribute or something else make it easier for me?
     
    , Aug 22, 2007
    #5
  6. Guest

    On 22 Aug, 09:16, wrote:
    > Thanks, Pete,
    > That fixed it up all right. It is a little annoying, though, to have
    > to write the namespace - could some change in the definition of the
    > attribute or something else make it easier for me?


    You could do:

    <xs:attributeGroup name="gr_reference">
    <xs:attribute ref="id" type="xs:string" use="optional"/
    >

    <!--xs:attribute ref="idtype" use="optional"/-->
    </xs:attributeGroup>

    Or:
    <xs:attributeGroup name="gr_reference">
    <xs:attribute ref="id" type="idType" use="optional"/>
    <!--xs:attribute ref="idtype" use="optional"/-->
    </xs:attributeGroup>

    <xs:simpleType name="idType">
    <xs:restriction base="xs:string"/>
    </xs:simpleType>

    i.e. use a type rather than a ref.

    HTH,

    Pete.
    =============================================
    Pete Cordell
    Codalogic
    for XML Schema to C++ data binding visit
    http://www.codalogic.com/lmx/
    =============================================
     
    , Aug 22, 2007
    #6
    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. Markus
    Replies:
    1
    Views:
    1,109
    Markus
    Nov 22, 2005
  2. Rick Razzano

    XSD document for XSD defintion

    Rick Razzano, Sep 26, 2003, in forum: XML
    Replies:
    1
    Views:
    493
    C. M. Sperberg-McQueen
    Sep 26, 2003
  3. Replies:
    1
    Views:
    865
    Martin Honnen
    Jan 14, 2004
  4. Peter Aberline

    xsd:any as a child of xsd:all

    Peter Aberline, Apr 5, 2004, in forum: XML
    Replies:
    0
    Views:
    794
    Peter Aberline
    Apr 5, 2004
  5. Bernd Oninger
    Replies:
    1
    Views:
    529
    Henry S. Thompson
    Jun 30, 2004
Loading...

Share This Page