Kind of global attribute
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 32
- Joined: Wed Jan 25, 2006 5:43 pm
Kind of global attribute
Hi,
I need the possibility to mark some attributes within an XML file as "unclear", meaning that the person who entered a value is not sure whether the value is correct or not (and no, it's not a matter of validation). So I thought it would be nice to have an additional attribute named unclear where the names of the unclear attributes could be listed. Seems to me as if I have to add this attribute to all elements of my XSD and that's what I want to avoid.
The question is if it is possible to define some kind of attribute at a single place that can be used in all my elements without having to define the usage over and over again. This may sound a little weird, but all ideas on solving the problem are truly appreciated.
Cheers
Alex
I need the possibility to mark some attributes within an XML file as "unclear", meaning that the person who entered a value is not sure whether the value is correct or not (and no, it's not a matter of validation). So I thought it would be nice to have an additional attribute named unclear where the names of the unclear attributes could be listed. Seems to me as if I have to add this attribute to all elements of my XSD and that's what I want to avoid.
The question is if it is possible to define some kind of attribute at a single place that can be used in all my elements without having to define the usage over and over again. This may sound a little weird, but all ideas on solving the problem are truly appreciated.
Cheers
Alex
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Alex,
The best approach I think will be to define a base type for all your elements types and there put the attribute you want to appear on all elements.
You can see a similar approach in the XML Schema for XSLT 2.0, look at generic-element-type and at versioned-element-type for intance:
http://www.w3.org/TR/xslt20/#schema-for-xslt
Best Regards,
George
The best approach I think will be to define a base type for all your elements types and there put the attribute you want to appear on all elements.
You can see a similar approach in the XML Schema for XSLT 2.0, look at generic-element-type and at versioned-element-type for intance:
http://www.w3.org/TR/xslt20/#schema-for-xslt
Best Regards,
George
-
- Posts: 32
- Joined: Wed Jan 25, 2006 5:43 pm
Hi George,
thanks for your answer. I thought about something like that, but still all the complexTypes and elements would have to use this base type and that requires a lot of adaptation work in a rather longish schema definition file. I gues there is no way to extend the XMLSchema <element> definition with an attribute and that's it???
Regards,
Alex
thanks for your answer. I thought about something like that, but still all the complexTypes and elements would have to use this base type and that requires a lot of adaptation work in a rather longish schema definition file. I gues there is no way to extend the XMLSchema <element> definition with an attribute and that's it???
Regards,
Alex
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
If you have global types for your elements then you can use redefine to redefine those types to allow the desired attribute. See below a working sample.
testRedefine.xsd
test.xsd
test.xml
Best Regards,
George
testRedefine.xsd
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="message"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="MessageType">
<xs:sequence>
<xs:element ref="type"/>
</xs:sequence>
</xs:complexType>
<xs:element name="message" type="MessageType"/>
<xs:element name="type" type="xs:string"/>
</xs:schema>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:redefine schemaLocation="testRedefine.xsd">
<xs:complexType name="MessageType">
<xs:complexContent>
<xs:extension base="MessageType">
<xs:attribute name="version" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
</xs:schema>
Code: Select all
<?xml version="1.0"?>
<test>
<message version="1.0">
<type>test</type>
</message>
</test>
George
-
- Posts: 32
- Joined: Wed Jan 25, 2006 5:43 pm
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Alex,
You can define an attribute as a global component in a schema file and then you can just refer to that instead of defining it in elements. The caveat hear is that the attribute will belong to the schema target namespace while if you define it in each element (that is locally) it will belong by default to no namespace unless you set the form to qualified.
Best Regards,
George
You can define an attribute as a global component in a schema file and then you can just refer to that instead of defining it in elements. The caveat hear is that the attribute will belong to the schema target namespace while if you define it in each element (that is locally) it will belong by default to no namespace unless you set the form to qualified.
Best Regards,
George
-
- Posts: 32
- Joined: Wed Jan 25, 2006 5:43 pm
Hi George,
sorry to bother you again, but correct me if I'm wrong. Assumed I define a global attribute like this
In order to use the attribute in "MyValue" I still have to add
to the element definition and. This is the step that I would somehow like to avoid. Therefore I thought about finding a way of defining the attribute only once and then it should automatically be available in all elements.
Cheers,
Alex
sorry to bother you again, but correct me if I'm wrong. Assumed I define a global attribute like this
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="myTargetNamespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="myTargetNamespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="MyValue">
<xs:complexType>
<xs:attribute name="Amount" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
<xs:attribute name="unclear" type="xs:string"/>
</xs:schema>
Code: Select all
<xs:attribute ref="unclear"/>
Cheers,
Alex
-
- Posts: 32
- Joined: Wed Jan 25, 2006 5:43 pm
Hi George,
that's what I feared...
I'm giving the global attribute a try, but now the next problem comes up. I've set elementFormDefault=qualified and attributeFormDefault=unqualified. This way the elements must be qualified and the attributes must not be qualified - unless the attribute is declared globally. Since my target/default namepspace does not use a prefix, but the global definition of the attribute requires me to use one, I'm stuck again
Cheers,
Alex
that's what I feared...
I'm giving the global attribute a try, but now the next problem comes up. I've set elementFormDefault=qualified and attributeFormDefault=unqualified. This way the elements must be qualified and the attributes must not be qualified - unless the attribute is declared globally. Since my target/default namepspace does not use a prefix, but the global definition of the attribute requires me to use one, I'm stuck again

Cheers,
Alex
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Alex,
The global attribute belons to the schema target namespace. The ref attribute value is a QName and it is resolved in the current namespace context where it appears. To use your example, if you have the target namespace also as default namespace then you do not need a prefix to refer to the attribute.
Anyway, as the attribute is defined in the target namespace when you will enter that attribute in an XML instance you always will need to qualify its name with a prefix bound to the schema target namespace (as attributes in instance documents do not use the default namespace).
Best Regards,
George
The global attribute belons to the schema target namespace. The ref attribute value is a QName and it is resolved in the current namespace context where it appears. To use your example, if you have the target namespace also as default namespace then you do not need a prefix to refer to the attribute.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="myTargetNamespace" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="myTargetNamespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="MyValue">
<xs:complexType>
<xs:attribute name="Amount" type="xs:integer" use="required"/>
<xs:attribute ref="unclear"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:attribute name="unclear" type="xs:string"/>
</xs:schema>
Best Regards,
George
-
- Posts: 32
- Joined: Wed Jan 25, 2006 5:43 pm
Hi George,
since my default name space does not use a prefix I had to put the global attribute into a seperate schema definition file with its own namespace. Then I just imported this namespace into my actual schema and used the prefix that I assigned to the new namespace with the global attribute. In other words: it works! Thanks for your help.
Best Regards,
Alex
since my default name space does not use a prefix I had to put the global attribute into a seperate schema definition file with its own namespace. Then I just imported this namespace into my actual schema and used the prefix that I assigned to the new namespace with the global attribute. In other words: it works! Thanks for your help.
Best Regards,
Alex
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