Hi,
No, you cannot do that in XML Schema alone. You can do that with
embedded Schematron rules inside XML Schema. Here it is a working
example:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="foo" type="foo">
<xs:annotation>
<xs:appinfo>
<pattern xmlns="http://www.ascc.net/xml/schematron" name="bar">
<rule context="foo">
<assert test="count(bar|@bar)=1">Either the element bar or
the attribute bar should be specified.</assert>
</rule>
</pattern>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="bar" type="xs:anyURI"/>
<xs:complexType name="foo">
<xs:sequence>
<xs:element minOccurs="0" ref="bar"/>
</xs:sequence>
<xs:attribute name="bar" default="" type="xs:anyURI"/>
</xs:complexType>
</xs:schema>
On a document like:
<foo bar="sample">
<bar>sample</bar>
</foo>
The following error will appear:
SystemID: C:\george\workspace\oXygen\samples\test.xml
Location: 1:0
Description: Either the element bar or the attribute bar should be
specified. (count(bar|@bar)=1)
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com