Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: validate xml-element against schema >Thread Next - Re: validate xml-element against schema Re: validate xml-element against schemaTo: 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?
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
