Validating XML Schema
-
Hi, By calling Dataset.WriteXml, my code produces XML as listed below. The user can also load the XML file, and I will use Dataset.ReadXML to do this. Preferably before calling that method, I would like to validate the schema of the XML to ensure that it has the same structure as an XML file produced by WriteXml. How can I do that? At present, I am loading the XML file and writing code like this: ValidXml = (LoadedOk) & (dsKeysAndValues.Tables[dsnKeysAndValues].Columns[KeyGroup] != null) & (dsKeysAndValues.Tables[dsnKeysAndValues].Columns[ValueGroup] != null) ; The code not only doesn’t work, but it also doesn’t seem elegant – if the XML file is large, it will take time just to load the file, before I can validate it. How can I validate the schema of XML to ensure that it matches what I am expecting? Thanks for your help, pointers, and time! Richard The mystery is out there – in the XML-Files (X-files music follows…) XML produced using WriteXml: K1 V9999
-
Hi, By calling Dataset.WriteXml, my code produces XML as listed below. The user can also load the XML file, and I will use Dataset.ReadXML to do this. Preferably before calling that method, I would like to validate the schema of the XML to ensure that it has the same structure as an XML file produced by WriteXml. How can I do that? At present, I am loading the XML file and writing code like this: ValidXml = (LoadedOk) & (dsKeysAndValues.Tables[dsnKeysAndValues].Columns[KeyGroup] != null) & (dsKeysAndValues.Tables[dsnKeysAndValues].Columns[ValueGroup] != null) ; The code not only doesn’t work, but it also doesn’t seem elegant – if the XML file is large, it will take time just to load the file, before I can validate it. How can I validate the schema of XML to ensure that it matches what I am expecting? Thanks for your help, pointers, and time! Richard The mystery is out there – in the XML-Files (X-files music follows…) XML produced using WriteXml: K1 V9999
Take a look at the
XmlValidatingReader
class. It's obsolete in .NET 2.0 but the MSDN topic also provides links to topics that present you what to use instead.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Take a look at the
XmlValidatingReader
class. It's obsolete in .NET 2.0 but the MSDN topic also provides links to topics that present you what to use instead.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
Hi Stefan, Thanks for your help. Richard