You don't declare default namespace in your xml document, so the validator
doesn't find the mainNode element in your schema. Change your xml file to
read:
<mainNode xmlns="http://myUrl.com">
...
</mainNode>
It doesn't look like you were using the other two namespaces, so I removed
them. If you need them, feel free to put them back. Also, you haven't
defined the default namespace in your schema, which might cause some
problems. Since you haven't posted the entire schema, I can't tell. And
finally, you might want to change the attributeFormDefault to "unqualified".
--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
[quoted text, click to view] <sorinuc@hotmail.com> wrote in message
news:1129138864.059839.10840@f14g2000cwb.googlegroups.com...
> Hi all,
>
> I'm quite desperate after so much time of frustration trying to
> validate an xml doc with a schema using XmlValidatingReader. I know I
> miss something but I cannot solve this for the life of me:
>
> My xsd is:
>
> <xs:schema targetNamespace="http://myUrl.com"
> elementFormDefault="qualified"
> attributeFormDefault="qualified" xmlns:a="http://myUrl.com"
> xmlns:xs="
http://www.w3.org/2001/XMLSchema"> > ...
> ...
> <xs:element name="mainNode">...
>
> The xml file is:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <mainNode xmlns:xsd="
http://www.w3.org/2001/XMLSchema" > xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" > xmlns:a="http://myUrl.com">
> ....
> other elements here...
> </mainNode>
>
> This is my code using XmlValidatingReader:
>
> Dim _reader As New XmlValidatingReader(xmlFragment,
> XmlNodeType.Element, Nothing)
> Dim _xsc As New XmlSchemaCollection
>
> __isValid = True
>
> _xsc.Add("http://myUrl.com", New XmlTextReader(schema))
>
> ' I have tried this as well:
> '_xsc.Add(Nothing, New XmlTextReader(schema))
>
> _reader.Schemas.Add(_xsc)
> _reader.ValidationType = ValidationType.Schema
>
> AddHandler _reader.ValidationEventHandler, AddressOf
> ValidationCallBack
>
> While _reader.Read()
> End While
> ...
>
> And the ValidationCallBack sub just changes the value of __isValid to
> false.
>
> Anytime I call the validation routine it returns false and the message
> error is:
> The 'mainNode' element is not declared. An error at , (..)
>
> If I changed the elementFormDefaul and attributeFormDefault to
> "unqualified" everything is fine.
>
> I would prefer buying you beer rather than banging my head against the
> walls.
>
> Paul
>