Groups | Blog | Home
all groups > dotnet xml > november 2006 >

dotnet xml : XML validation of single value without entire XML document


Bardo
11/29/2006 12:00:00 AM
Hi all,

Does anyone know if it is possible, and if so how, to perform validation of
a simple non XML string against certain XSD restrictions, without having the
entire XML document to validate against the schema.
To elaborate -
- Within XSD certain restrictions are defined for a particular
element/attribute, such as datatype, minlength, maxlength, valid enumeration
values etc.
Is it at all possible to validate a simple string value against these
restrictions defined within the schema.
I.e. I do not have the entire XML document that matches the schema. I do not
even have any XML at all - I simply have a string value which represents one
of the elements' values in the schema. I would like to utilise the power of
XSD to validate the value, rather than writing my own code to check the
datatype, length, allowed values etc.

Any suggestions appreciated!

Thanks,

Bardo

Martin Honnen
11/29/2006 4:38:03 PM
[quoted text, click to view]

With .NET 2.0 and later the XmlDocument has a method called Validate
where you can pass in a single node to be validated. So you will at
least to create e.g. an element node and pass that to the validate method.

Then, also in .NET 2.0 and later, there is the XmlSchemaValidator class
that has method likes ValidateAttribute, ValidateElement, ValidateText
that allows you to validate certain components.

--

Martin Honnen --- MVP XML
Bardo
11/30/2006 12:00:00 AM
Thanks Martin, the XmlSchemaValidator looks like what I'm after!

[quoted text, click to view]

AddThis Social Bookmark Button