If you really want to keep the document structure and none of the above
alternatives solve your problem then you have also the following
possibilities:
A. Make both attributes optional and use Schematron embedded rules in
XML Schema to check that you have only one of them
B. Use Relax NG instead of XML Schema
Here it is a sample for case A. XML Schema with embedded Schematron
rules:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sch="http://www.ascc.net/xml/schematron">
<xs:element name="test">
<xs:annotation>
<xs:appinfo>
<sch:pattern name="Check that we have only one attribute.">
<sch:rule context="test">
<sch:assert test="count(@p|@c)=1">Ony one of the attributes
p and c can be
specified.</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:attribute name="p" type="xs:string" use="optional"/>
<xs:attribute name="c" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
</xs:schema>
on the document
<test c="1" p="2"/>
will give:
SystemID: C:\george\workspace\oXygen\samples\test.xml
Location: 1:0
Description: Ony one of the attributes p and c can be specified.
(count(@p|@c)=1)
And here it is a Relax NG sample schema:
<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="test">
<choice>
<attribute name="c">
<data type="string"/>
</attribute>
<attribute name="p">
<data type="string"/>
</attribute>
</choice>
</element>
</start>
</grammar>
And in compact syntax that is:
default namespace = ""
start =
element test {
attribute c { xsd:string }
| attribute p { xsd:string }
}
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com