xsd:attribute use="required" validation question
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 4
- Joined: Fri Oct 31, 2003 12:48 am
xsd:attribute use="required" validation question
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
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Dear Thatcher,
When you define a top level attribute it belongs to the schema target namespace, in your case the target namespace is "myNamespace". In order to enter an attribute from a specified namespace you should qualify it with a prefix pointing to that namespace, if no prefix is specified the attribute belongs to no namespace. Thus if you change your sample to look like:
You will not get the attribute related error anymore.
I admit the error message is not very helpful in this case, the first error should say that the guid attribute from no namespace is not allowed and the second error should say that attribute guid from the "myNamespace" namespace must appear.
Best Regards,
George
When you define a top level attribute it belongs to the schema target namespace, in your case the target namespace is "myNamespace". In order to enter an attribute from a specified namespace you should qualify it with a prefix pointing to that namespace, if no prefix is specified the attribute belongs to no namespace. Thus if you change your sample to look like:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<object xmlns="myNamespace" xmlns:x="myNamespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="myNamespace structure.xsd"
x:guid="1234"></object>
I admit the error message is not very helpful in this case, the first error should say that the guid attribute from no namespace is not allowed and the second error should say that attribute guid from the "myNamespace" namespace must appear.
Best Regards,
George
-
- Posts: 4
- Joined: Fri Oct 31, 2003 12:48 am
George,
Thanks for your reply, however, I'm thoroughly confused. I have been searching the web for a definative answer but I can't find one. So I'll ask here even though I'm sure you are tired of correcting xml mistakes instead of supporting real oxygen questions. Here it is:
I thought that by specifying xmlns="myNamespace" that all elements without a namespace prefix use this namespace, and that all attributes use the elements namespace unless excplicitly prefixed by another. Am I mistaken?
Thanks again, your team has created a very useful tool, and unfortunatly is helping me discover just how little xml I really know.
Thatcher
Thanks for your reply, however, I'm thoroughly confused. I have been searching the web for a definative answer but I can't find one. So I'll ask here even though I'm sure you are tired of correcting xml mistakes instead of supporting real oxygen questions. Here it is:
I thought that by specifying xmlns="myNamespace" that all elements without a namespace prefix use this namespace, and that all attributes use the elements namespace unless excplicitly prefixed by another. Am I mistaken?
Thanks again, your team has created a very useful tool, and unfortunatly is helping me discover just how little xml I really know.
Thatcher
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service