Hi all,
I'm quite desperate after so much time of frustration trying to
validate an xml doc with a schema using XmlValidatingRe ader. I know I
miss something but I cannot solve this for the life of me:
My xsd is:
<xs:schema targetNamespace ="http://myUrl.com"
elementFormDefa ult="qualified"
attributeFormDe fault="qualifie d" 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 XmlValidatingRe ader:
Dim _reader As New XmlValidatingRe ader(xmlFragmen t,
XmlNodeType.Ele ment, Nothing)
Dim _xsc As New XmlSchemaCollec tion
__isValid = True
_xsc.Add("http://myUrl.com", New XmlTextReader(s chema))
' I have tried this as well:
'_xsc.Add(Nothi ng, New XmlTextReader(s chema))
_reader.Schemas .Add(_xsc)
_reader.Validat ionType = ValidationType. Schema
AddHandler _reader.Validat ionEventHandler , AddressOf
ValidationCallB ack
While _reader.Read()
End While
....
And the ValidationCallB ack 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 elementFormDefa ul and attributeFormDe fault to
"unqualifie d" everything is fine.
I would prefer buying you beer rather than banging my head against the
walls.
Paul