Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Schema - Definition for checking part of schema ? (http://www.velocityreviews.com/forums/t167671-schema-definition-for-checking-part-of-schema.html)

Abhinav 08-16-2004 04:18 PM

Schema - Definition for checking part of schema ?
 
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

Martin Honnen 08-16-2004 04:46 PM

Re: Schema - Definition for checking part of schema ?
 


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:xs="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/


Abhinav 08-16-2004 05:04 PM

Re: Schema - Definition for checking part of schema ?
 
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:xs="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

Martin Honnen 08-16-2004 05:33 PM

Re: Schema - Definition for checking part of schema ?
 


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/


Abhinav 08-16-2004 05:44 PM

Re: Schema - Definition for checking part of schema ?
 
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

Martin Honnen 08-16-2004 05:50 PM

Re: Schema - Definition for checking part of schema ?
 


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/


Abhinav 08-16-2004 06:24 PM

Re: Schema - Definition for checking part of schema ?
 
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


All times are GMT. The time now is 03:57 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57