default value of attribute depends on attribute of parent
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 1
- Joined: Thu Mar 16, 2006 3:25 pm
default value of attribute depends on attribute of parent
Post by Menno Pruijssers »
Ey Guys,
I a creating a schema for a xml file like this:
My schema looks like this:
The 'package' attribute of the 'class'-element is optional. If not specified: the package attribute of the 'root'-element must be used. Is it possible to model this. It is needed foor the key.
I a creating a schema for a xml file like this:
Code: Select all
<root package="com.test">
<class name="Class">
....
</class>
<class package="com.test2">
....
</class>
</root>
Code: Select all
<xsd:element name="root" type="RootType">
<xsd:key name="className">
<xsd:selector xpath=".//class"/>
<xsd:field xpath="@name"/>
<xsd:field xpath="@package"/>
</xsd:key>
</xsd:element>
<xsd:complexType name="RootType">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="1" type="ClassType" name="class"/>
</xsd:sequence>
<xsd:attribute name="package" use="optional" type="PackageNameType"/>
</xsd:complexType>
<xsd:complexType name="ClassType">
....
</xsd:complexType>
<xsd:simpleType name="PackageNameType">
<xsd:restriction base="strippedString">
<xsd:pattern value="([a-z][a-zA-Z0-9]*.)*"/>
</xsd:restriction>
</xsd:simpleType>
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
Hello,
XML Schema does not allow to specify that if an optional attribute is not specified for an element in an XML document that attribute takes the value of some attribute of other element. The possible values of an attribute, optional or not must be specified statically in the schema as string constants, not as values of an attribute from other element.
Regards,
Sorin
XML Schema does not allow to specify that if an optional attribute is not specified for an element in an XML document that attribute takes the value of some attribute of other element. The possible values of an attribute, optional or not must be specified statically in the schema as string constants, not as values of an attribute from other element.
Regards,
Sorin
-
- Posts: 32
- Joined: Wed Jan 25, 2006 5:43 pm
Hi,
in addition to this I'm having another question:
I have an element that shall express a value either as a certain date or a date interval, e.g <Arrival Date="" From="" Until=""/>, so either Date or From and Until have to be set, but not all of them. Is there a possiblity to create a schema definition for this matter?
Kind Regards
- Alex
in addition to this I'm having another question:
I have an element that shall express a value either as a certain date or a date interval, e.g <Arrival Date="" From="" Until=""/>, so either Date or From and Until have to be set, but not all of them. Is there a possiblity to create a schema definition for this matter?
Kind Regards
- Alex
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Alex,
No, you cannot do this in XML Schema. You can do that however either with XML Schema with embedded Schematron rules or with a Relax NG schema, all being supported by oXygen.
Here it is a sample XML Schema with embedded Schematron rules:
Here it is a sample Relax NG Schema
in compact syntax
in XML syntax
Best Regards,
George
No, you cannot do this in XML Schema. You can do that however either with XML Schema with embedded Schematron rules or with a Relax NG schema, all being supported by oXygen.
Here it is a sample XML Schema with embedded Schematron rules:
Code: Select all
<?xml version='1.0' encoding='UTF-8'?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Arrival">
<xs:annotation>
<xs:appinfo>
<pattern xmlns="http://www.ascc.net/xml/schematron" name="Check attributes">
<rule context="Arrival">
<assert test="(@Date and not(@From or @Until))or (not(@Date) and @From and @Until)">
Either specify Date or both From and Until attributes.</assert>
</rule>
</pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:attribute name="Date"/>
<xs:attribute name="From"/>
<xs:attribute name="Until"/>
</xs:complexType>
</xs:element>
</xs:schema>
in compact syntax
Code: Select all
default namespace = ""
start =
element Arrival {
attribute Date { text }
| (attribute From { text },
attribute Until { text })
}
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<element name="Arrival">
<choice>
<attribute name="Date"/>
<group>
<attribute name="From"/>
<attribute name="Until"/>
</group>
</choice>
</element>
</start>
</grammar>
George
-
- Posts: 26
- Joined: Wed Aug 24, 2005 10:47 am
but how can I activate it?
Hi,
I tried to apply this, but nothing happened. This is how I tried to build it in:
By using assert and report on the same test, I wanted to make sure that I get a reaction, but nothing happens when validating my document. Do I have to turn something on before?
Regards,
Frank
I tried to apply this, but nothing happened. This is how I tried to build it in:
Code: Select all
<xs:element name="sp">
<xs:annotation>
<xs:documentation>Syntactic particle. This includes rnam dbye (case-marking particles), phrad rang dbang can
(independent particles) and phrad gzhan dbang can (dependent particles)</xs:documentation>
<xs:appinfo>
<pattern xmlns="http://www.ascc.net/xml/schematron" name="Check attributes">
<rule context="sp">
<assert test="@type">type nicht da </assert>
<report test="@type">type ist da</report>"
</rule>
</pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="type">
....
...
Regards,
Frank
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Frank,
To have the Schematron validation and the XML Schema validation in a single action then you need to associate the schema both as an XML Schema and as a Schematron Schema in the document. For instance let's suppose you have the schema test.xsd associated with the xsi:noNamepsaceSchemaLocation attribute then you should add also a PI like
<?oxygen SCHSchema="test.xsd"?>
before the root element. This is added automatically by the Associate schema action if you select the Schematron page and select the same XML Schema. oXygen will automatically detect that it is an XML Schema and will try to extract the Schematron rules from that and use them for the Schematron validation.
Note however that if your element sp belongs to a namespace then you need to use a prefix to match that in the rule and declare that prefix like:
<sch:ns prefix="p" uri="yourNamespace"/>
and use p:sp instead of sp.
Best Regards,
George
To have the Schematron validation and the XML Schema validation in a single action then you need to associate the schema both as an XML Schema and as a Schematron Schema in the document. For instance let's suppose you have the schema test.xsd associated with the xsi:noNamepsaceSchemaLocation attribute then you should add also a PI like
<?oxygen SCHSchema="test.xsd"?>
before the root element. This is added automatically by the Associate schema action if you select the Schematron page and select the same XML Schema. oXygen will automatically detect that it is an XML Schema and will try to extract the Schematron rules from that and use them for the Schematron validation.
Note however that if your element sp belongs to a namespace then you need to use a prefix to match that in the rule and declare that prefix like:
<sch:ns prefix="p" uri="yourNamespace"/>
and use p:sp instead of sp.
Best Regards,
George
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