Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: validate xml-element against schema

From: hill@--------.--
To: NULL
Date: 10/31/2008 1:07:00 AM
On 30 Okt., 17:43, Martin Honnen <mahotr...@yahoo.de> wrote:
> _at_ wrote:
> > The error I got is:
>
> > "The 'user' element is not declared."
>
> > Could anybody give me a hint?
>
> > Here is the code-snippet:
>
> > =A0 =A0 =A0 public void checkXmlFragment()
> > =A0 =A0 =A0 {
>
> > =A0 =A0 =A0 =A0 =A0string xml =3D @"<user id=3D""jon""
> > pwd=3D""pass""><roles><role>Admin</role></roles></user>";
>
> The root element in your XML sample is named 'user' while your schema bel=
ow:
>
> > <xs:schema elementFormDefault=3D"unqualified"
> > xmlns:xs=3D"http://www.w3.org/2001/XMLSchema">
> > <xs:element name=3D"users">
>
> defines exactly one possible root element named 'users'.
>
> So you have the choice to either change the XML sample and wrap the
> 'user' element into a 'users' element or you need to change the schema
> and allow 'user' as a root element e.g.
>
> <xs:schema elementFormDefault=3D"unqualified"
> xmlns:xs=3D"http://www.w3.org/2001/XMLSchema">
> =A0 =A0<xs:element name=3D"users">
> =A0 =A0 =A0<xs:complexType>
> =A0 =A0 =A0 =A0<xs:sequence>
> =A0 =A0 =A0 =A0 =A0<xs:element ref=3D"user" minOccurs=3D"0" maxOccurs=3D"=
unbounded">
> =A0 =A0 =A0 =A0 =A0</xs:element>
> =A0 =A0 =A0 =A0</xs:sequence>
> =A0 =A0 =A0</xs:complexType>
> =A0 =A0</xs:element>
> =A0 =A0<xs:element name=3D"user">
> =A0 =A0 =A0<xs:complexType>
> =A0 =A0 =A0 =A0<xs:sequence>
> =A0 =A0 =A0 =A0 =A0<xs:element name=3D"roles" minOccurs=3D"0" maxOccurs=
=3D"1">
> =A0 =A0 =A0 =A0 =A0 =A0<xs:complexType>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0<xs:sequence minOccurs=3D"0" maxOccurs=3D"unbo=
unded">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<xs:element name=3D"role" type=3D"xs:strin=
g">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</xs:element>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0</xs:sequence>
> =A0 =A0 =A0 =A0 =A0 =A0</xs:complexType>
> =A0 =A0 =A0 =A0 =A0</xs:element>
> =A0 =A0 =A0 =A0</xs:sequence>
> =A0 =A0 =A0 =A0<xs:attribute name=3D"id" type=3D"xs:string"/>
> =A0 =A0 =A0 =A0<xs:attribute name=3D"pwd" type=3D"xs:string"/>
> =A0 =A0 =A0</xs:complexType>
> =A0 =A0</xs:element>
> </xs:schema>
> --
>
> =A0 =A0 =A0 =A0 Martin Honnen --- MVP XML
> =A0 =A0 =A0 =A0http://JavaScript.FAQTs.com/

Thanks for the answer.
Does it mean, there is no way to check
an element, that is not one of the possible
root-elements in the schema?

I'm trying to check only an element
that is part of the possible root-element.
( e.g. user, roles or role in the sample)

Any further ideas?



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent