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.ValidationFlags =
XmlSchemaValidationFlags.ReportValidationWarnings
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 XmlReaderSettings = New XmlReaderSettings()
settings.Schemas.Add(Nothing, schemaFilePath)
settings.ValidationType = ValidationType.Schema
settings.ValidationFlags = settings.ValidationFlags And
XmlSchemaValidationFlags.ReportValidationWarnings
AddHandler settings.ValidationEventHandler, New
ValidationEventHandler(AddressOf ValidationEventHandler)
Using Reader As XmlReader = XmlReader.Create(New
StringReader(xmlCommandString), settings)
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(Reader)
That way the XmlReader will do the validation and report warnings and
errors to the ValidationEventHandler.
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/