Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Schema - Definition for checking part of schema ?

Reply
Thread Tools

Schema - Definition for checking part of schema ?

 
 
Abhinav
Guest
Posts: n/a
 
      08-16-2004
Hi,

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 ?

TIA

--
Abhinav
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      08-16-2004


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
xmlnss="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>

--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
 
Abhinav
Guest
Posts: n/a
 
      08-16-2004
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
> xmlnss="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
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      08-16-2004


Abhinav wrote:

> 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 :


Is the number of elements before <aa> known? Otherwise I think you get a
problem with the schema being non-deterministic.

--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
Abhinav
Guest
Posts: n/a
 
      08-16-2004
Martin Honnen wrote:
>
> Abhinav wrote:
>
>
>>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 :

>
>
> Is the number of elements before <aa> known? Otherwise I think you get a
> problem with the schema being non-deterministic.
>

Hmm ..

It is not known .. but it is definitely more than 1.

Putting maxOccurs="10" (An arbotrary value I can live with) did not solve
the problem ..

Do you mean to say that it is not possible to do it at all ? (I read the
Schema specs on w3c.org, but could not find to many pointers.

TIA

--

Abhinav
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      08-16-2004


Abhinav wrote:


>> Is the number of elements before <aa> known? Otherwise I think you get
>> a problem with the schema being non-deterministic.
>>


> It is not known .. but it is definitely more than 1.
>
> Putting maxOccurs="10" (An arbotrary value I can live with) did not
> solve the problem ..
>
> Do you mean to say that it is not possible to do it at all ?


From my current understanding and tests with Xerces-J and MSXML you
need to specify a fixed number of occurances otherwise the parser is
unable to determine where the element you want to check for is. But
maybe someone else comes up with a workaround.

--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
Abhinav
Guest
Posts: n/a
 
      08-16-2004
Martin Honnen wrote:
>
> Abhinav wrote:
>
>
>
>>>Is the number of elements before <aa> known? Otherwise I think you get
>>>a problem with the schema being non-deterministic.
>>>

>
>
>>It is not known .. but it is definitely more than 1.
>>
>>Putting maxOccurs="10" (An arbotrary value I can live with) did not
>>solve the problem ..
>>
>>Do you mean to say that it is not possible to do it at all ?

>
>
> From my current understanding and tests with Xerces-J and MSXML you
> need to specify a fixed number of occurances


Even the fixed number of occurences does not work in Xerces-P ! The only
thing that works in minOccurs=maxOccurs=1.

otherwise the parser is
> unable to determine where the element you want to check for is. But
> maybe someone else comes up with a workaround.


Regards
--
Abhinav
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time template list definition / Run-time variable type definition Pierre Yves C++ 2 01-10-2008 02:52 PM
Automagic determination of definition based on definition location. Jon Slaughter C++ 4 10-26-2005 05:00 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
can a class definition inside another class's definition Jianli Shen C++ 1 03-13-2005 06:02 PM
help?: incomplete definition with complete definition in scope Ark C Programming 1 08-07-2004 04:21 PM



Advertisments