I'm fixing warnings in my program and apparently xmlvalidating reader and xmlschemacollection is obsolete. Here's an attempt at "mimicking" the previous validation function with the new one involving xmlschemaset and xmlreader.create.I first declare a schema, and set it using the targeturi string, then add it to the schemaset while setting up the validation event handler. Length - 3) "xsd"; Xml Schema xsd = new Xml Schema(); xsd. Length - 3) "xsd"; Xml Schema xsd = new Xml Schema(); xsd. Read(schema Reader, Schema Validation Handler); asset. Files (1 xsd, 2 xml) and full C# code here: gist.github.com/kiquenet/86090779650975b7426a7f798174eef6Xml Reader Settings settings = new Xml Reader Settings(); settings.
I knew how to do it with xmlvalidating reader, but that isn't an option if I want to fix these warnings. During testing, only the new validation xml code was used, the old one was commented out. Validation Event Handler = new Validation Event Handler(Validation Call Back); ss. Count Unfortunately, when I run the program and try to validate an invalid xml document, it gives me an error like this: "The 'URNLookup' element is not declared." The URNLookup element is the root element of the xml file. I'll be happy to provide additional information if I missed any. Validation Event Handler = new Validation Event Handler(Validation Call Back); ss. Count The was changed to have a namespace, and the file string.
When the program encounters the invalid node, the method Validation Error is called that displays a message explaining why validation failed. An object of the class Xml Schema Set stores a collection of schemas that an Xml Reader can be validated against.
It assigns a new Xml Schema Set object to variable schemas, and calls this object's Add method to add a schema to the collection.
This is also true for applications that process smaller XML files. The situation is similar to database resultset - you have to iterate (read method of XMLReader) through document nodes and each node is validated only when you read it (sometimes even later) My Example: 18 MB xml with 258.230 lines Result: XMLReader - 656.14199638367 ms, 379064 bytes DOMDocument - 483.04295539856 ms, 369280 bytes So i decided to go with DOMDocument, but just try it with your own xml and xsd and use your faster choice.
There are a lot of manuals in the web about this validating procedure.