I'm creating a system that uses XML to store an audit trail of the
steps that it has been through in the system.
The way the schema is defined, there is a "Tag" for every application
that performs modifications to any data, and "Fields" inside the tag
that outline the changes that were made.
Applications in the flow of the system read in these XML files and will
"overlay" these tags in order to obtain data for all fields that were
modified from a certain point on to act on that data and post their
results.
By the end of the system, as you can see, there are many, many Tags in
these XML files, and using an XSD schema to validate the file when it's
read in is horribly inefficient. Rather, I would like to define the
schema in such a way that it will be a validator for only the Tags and
their contents, and apply that schema to the tags that are written in.
Currently, I have tried to do this 2 ways, one way using a validating
reader and trying to .Skip() tags that are not needed at the current
point, and the other was to use an XmlDocument to perform validation on
fragments of XML.
The problem I saw, however, was that according to MSDN documentation,
..Skip() on a validating reader validates the XML that it is skipping!
(Doesn't make much sense, huh). So I had to modify how I used the
ValidatingReader:
.. Create an XmlValidatingReader for the xml file to be read in
.. If a tag is found that should not be validated (not needed by the
current application), valReader.MoveToNextAttribute() and
valReader.MoveToElement() until the tag is complete.
The second way, using an XmlDocument and fragment validation, was
attempted like this:
.. Create an XmlTextReader for the xml file to be read in
.. Create an XmlDocument from the text reader
.. Get all "Tags" from the element list of the document
.. Loop through the resulting list and if the Name of the tag is one we
need to validate, create an XmlValidatingReader for the .OuterXml of
the node and .Read() on the ValidatingReader.
The problem with both of these algorithms is that the overhead of
creating the reader and document, moving the cursor manually, and all
the other manual operations proved to negate any benefit (according to
Durations set in the code to time the sections) versus just creating a
ValidatingReader and passing that to the Deserialize function.
Currently this is what I'm doing, and the hit for Validating while
Deserializing is huge. So I want to do my own small validation, and
pass just an XmlTextReader to the Deserialize function.
Any Ideas?
Thanks!