XML element validation with XSD

b4u

Golden Member
Nov 8, 2002
1,380
2
81
Hi,

I have a question regarding XML and XSD validation.

This question came from a discussion with a colleage, and so here I am trying to figure out who will end up victorious and by the lunch :D

Let's go then!

I have a possible XML message, like:

<root>
<name>Someone Here</name>
<email>someone.here@gmail.com</email>
</root>

Then I have the following extract from XSD, for the "email" element:

<xs:element name="email" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

Here I defined in my XSD that the "email" element is optional, and it's type is "xs:string" with a minimum of 1 char.

Now the way I see it, I can simply throw:
<root>
<name>Someone Here</name>
</root>
and it will comply with XSD schema, but if I send:
<root>
<name>Someone Here</name>
<email></email>
</root>
it will fail miserably, correct?

My colleage told me about a possibility to configure it as "qualified" or "unqualified" element, which would allow me to receive "<email></email>" without breaking when checked against XSD.

I have serious doubt that it is possible, since the XSD defines that it is an optional element, and WHEN it EXISTS, it MUST be a String with minimum 1 char.

So am I correct? Or am I correct?

I hope so ... or if not, please point me the direction to read info about it.


Many Thanks
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I don't know what your friend means. Qualified and unqualified elements refer to the presence of namespace qualifiers, or the lack of them. If it has some effect on allowing or disallowing certain instances when validating against a particular schema, I haven't heard of it but would suspect it to be a side effect if I did hear of it :).

I think you're right. If the element is optional, then it may or may not appear. If it appears, then it must adhere to the content restrictions. But I am no xsd guru, so we'll have to see what the others say.