Apply Embedded XSD schema to specific element in an XmlDocument



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!

.



Relevant Pages

  • Re: GEDOM as a database format
    ... and how those tags can generate both display text ... in free-form text with XML tags and attributes to carry the linking ... definition of it's elements be shared (by a schema, ... among everyone about a core set of tags that everything will fit into. ...
    (soc.genealogy.computing)
  • Re: GEDOM as a database format
    ... and how those tags can generate both display text ... in free-form text with XML tags and attributes to carry the linking ... definition of it's elements be shared (by a schema, ... and that would create 'live objects' from those references when the text was ...
    (soc.genealogy.computing)
  • Re: Getting NASM from C
    ... > format we were going to edit it in... ... all XML is? ... HTML is a specific "subset" of XML for displaying ... it's a text file with "tags" inside ...
    (alt.lang.asm)
  • Re: HOWTO: Use custom XML schemas with VS.NET 2003
    ... Christoph, when the VS 2005 beta comes out, or if you're an MSDN subscriber ... The reason I ask is that the XML editor ... > recognize the XML schema I've created for the control template files. ... or add it to the project that contains your XML files. ...
    (microsoft.public.vsnet.ide)
  • Re: Gotta start somewhere ... how many of us are really out there?
    ... if you are thinking of using XML ... pure shell commands ... ... or whatever XML tags you want to use using the acutal ... accompish all this in hindsight,as all the commands ...
    (freebsd-questions)