xsd:attribute use="required" validation question
Posted: Fri Oct 31, 2003 1:24 am
Hi,
I am a new trial user with the latest eclipse 3.0.0 and oxygenxml plugin for eclipse. I have written several schemas, lets call the first components.xsd and the later structure.xsd. The first looks something like:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="myNamespace"
xmlns:"myNamespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xsd:attribute name="guid" type="xsd:int"/>
</xsd:schema>
The second looks like:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="myNamespace"
xmlns:"myNamespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xsd:include schemaLocation="component.xsd"/>
<xsd:element name="object">
<xsd:complexType>
<xsd:attribute ref="guid" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Both schemas are well-formed and validate as proper xsd. When I create a new xml file which points to that schema for validation, in this case object must be the root and my xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<object xmlns:"myNamespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="myNamespace file:/home/me/xml/schema/structure.xml"
guid="1234">
</object>
When I validate I get two error messages, one says:
cvc-complex-type.3.2.2: Attribute 'guid' is not allowed to appear in element 'object'.
While the other says:
cvc-complex-type.4: Attribute 'guid' must appear in element 'object'.
This behavior happens at all levels of my xml for more complex schema, ie not just for attributes in the root node, and it doesn't happen if the attribue is optional; however, I tried to simplify it to the most basic case. The interesting thing is that the autocompletion works perfectly less the attribute for the root node. I may be doing something stupid though, as it woluldn't be the first time
Thanks for any insight.
Thatcher
I am a new trial user with the latest eclipse 3.0.0 and oxygenxml plugin for eclipse. I have written several schemas, lets call the first components.xsd and the later structure.xsd. The first looks something like:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="myNamespace"
xmlns:"myNamespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xsd:attribute name="guid" type="xsd:int"/>
</xsd:schema>
The second looks like:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="myNamespace"
xmlns:"myNamespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xsd:include schemaLocation="component.xsd"/>
<xsd:element name="object">
<xsd:complexType>
<xsd:attribute ref="guid" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Both schemas are well-formed and validate as proper xsd. When I create a new xml file which points to that schema for validation, in this case object must be the root and my xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<object xmlns:"myNamespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="myNamespace file:/home/me/xml/schema/structure.xml"
guid="1234">
</object>
When I validate I get two error messages, one says:
cvc-complex-type.3.2.2: Attribute 'guid' is not allowed to appear in element 'object'.
While the other says:
cvc-complex-type.4: Attribute 'guid' must appear in element 'object'.
This behavior happens at all levels of my xml for more complex schema, ie not just for attributes in the root node, and it doesn't happen if the attribue is optional; however, I tried to simplify it to the most basic case. The interesting thing is that the autocompletion works perfectly less the attribute for the root node. I may be doing something stupid though, as it woluldn't be the first time
Thanks for any insight.
Thatcher