This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > August 2005 > XSD validation help!





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author XSD validation help!
natalia

2005-08-13, 7:23 pm


hi, i am new to XSD tech and need help now.
1. I basically wanted to know if its possible for me to get a value of
an element/ attribute and match with the value of some other
element/attribute, thru some expression or something

2. And can we check something like element <B> should be there(ie
mandatory) if <A> is present. And here <B> is not a sub element of <A>,
it is placed somewhere down the XML file. Is it possible to confirm this
with references?

thanx in advance



--
natalia
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Chris Lovett

2005-08-14, 4:19 am

1. Standard XSD does not provide a way to do this. You have to add
something else for that (usually code or database layer).

2. You can use a thing called ID/IDREF where elements or attributes of type
IDREF must have a matching element "anywhere in the document" or attribtue
of type ID. For example:

<xs:element name="root">
<xs:complexType >
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="a">
<xs:complexType>
<xs:attribute name="ref" type="xs:IDREF"/>
</xs:complexType>
</xs:element>
<xs:element name="b">
<xs:complexType>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>

Then the following document is in error:

<root xmlns="http://test" >
<a ref="x"/>
</root>

The error says "Reference to undeclared ID is 'x' ".

The following are valid according to this schema:

<root xmlns="http://test" >
<b id="x"/>
<a ref="x"/>
</root>

and

<root xmlns="http://test" >
<a ref="x"/>
<b id="x"/>
</root>

Notice that you cannot limit the order of id attributes to just AFTER the
reference.


"natalia" <natalia.1tph8c@mail.codecomments.com> wrote in message
news:natalia.1tph8c@mail.codecomments.com...
>
> hi, i am new to XSD tech and need help now.
> 1. I basically wanted to know if its possible for me to get a value of
> an element/ attribute and match with the value of some other
> element/attribute, thru some expression or something
>
> 2. And can we check something like element <B> should be there(ie
> mandatory) if <A> is present. And here <B> is not a sub element of <A>,
> it is placed somewhere down the XML file. Is it possible to confirm this
> with references?
>
> thanx in advance
>
>
>
> --
> natalia
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>



Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews