Martin Honnen wrote:
>
> Abhinav wrote:
>
>
>
>>I have an xml which contains the following
>>
>><a>
>> <!-- aa Is what I am interested in -->
>> <aa>
>> </aa>
>>
>> <bb></bb>
>> <cc></cc>
>>
>></a>
>>
>>Here, my application requires that <a> (The root element) *must* contain
>><aa> tag.
>>
>>However, tags such as <bb>, <cc>, or anything else might exist - they
>>are optional, and I do not know which of them (if at all) will be present.
>>
>>How do I write the schema for it ?
>>
>>Using all requires that I know which tags might appear ..
>>
>>Using any doesnt allow me to check the presence of the specific tag <aa>
>>
>>Any pointers on how to achieve this ?
>
>
> It is simple, use a sequence with one defined element and xs:any:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema
> xmlns
s="http://www.w3.org/2001/XMLSchema"
> version="1.0">
>
> <xs:element name="a">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="aa" type="xs:string" />
> <xs:any processContents="lax" maxOccurs="unbounded" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> </xs:schema>
>
Thanks .. That worked ..
However, If I want to ignore elements both *before* and *after* <aa> ?
adding another <xs:any> before <xs:element name="aa"> does not work.
XML::Xerces gives the error :
MESSAGE: Not enough elements to match content model : '((,aa),)'
Any pointers appreciated!
TIA
--
Abhinav