Search code examples
c#.netxmlxsdxsd-1.0

Validating single XML node against entire schema


I am developing a serializer which should be compliant with an already existent, big and well defined schema. In order to unit test my serialization and attributes (which define how things are serialized) I want to use unit testing.

The problem is that I want to unit test element by element.

For example: This Schema has an element called ide, this element has another elements within it. On my project I have an object which represents this ide element.

In my test method I create an instance of this object and generate a xml on which this ide element is the root. I want to be able to validate this single xml node using the entire xsd.

How would I go about doing this?

The only thing that came to mind and seems too much trouble is to modify the schema on the fly, so it has only the elements that interest me on the given moment. I tested and verified that this would work, but would be bad for maintenance.

What is the correct way to achieve this?


Solution

  • I was finally able to answer the question. You have to use XElement.Validate