What's wrong with this XSD?

U

uridor

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>
 
U

usenet

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/
=============================================
 
U

uridor

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
 
U

usenet

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/
=============================================
 
U

uridor

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?
 
U

usenet

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: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/
=============================================
 

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
473,818
Messages
2,569,736
Members
45,709
Latest member
DRISenaida

Latest Threads

Top