Doug wrote:
Hi Martin, so if I understood you correctly part of the issue is that
my sample did not have a targetNamespace within (I think that is what
that blog was talking about too). But, I added this line of code into
my application and it did not even report the warning that the blog
talked about.
settings.Valida tionFlags =
XmlSchemaValida tionFlags.Repor tValidationWarn ings
As I tried to point out in my previous response, it is unfortunately not
possible to report warnings with the Validate method.
Is there another way to do this validation then the way I'm doing it?
Yes, the Validate method is mostly meant to Validate an XmlDocument that
has been manipulated with e.g. CreateElement/AppendChild.
If you simply want to validate your XML string you can do it directly
when parsing it e.g. (pseudo code)
Dim settings As XmlReaderSettin gs = New XmlReaderSettin gs()
settings.Schema s.Add(Nothing, schemaFilePath)
settings.Valida tionType = ValidationType. Schema
settings.Valida tionFlags = settings.Valida tionFlags And
XmlSchemaValida tionFlags.Repor tValidationWarn ings
AddHandler settings.Valida tionEventHandle r, New
ValidationEvent Handler(Address Of ValidationEvent Handler)
Using Reader As XmlReader = XmlReader.Creat e(New
StringReader(xm lCommandString) , settings)
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(Rea der)
That way the XmlReader will do the validation and report warnings and
errors to the ValidationEvent Handler.
You do not need an XmlDocument at all to do the validation, the
XmlReader would suffice plus a simple loop that reads through the XML
document but your earlier code snippets looked as if you use the
XmlDocument elsewhere so I have left that in.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/