>I have created my schema format(xxx.xsd) for my xml files, but how can I
>use it validate my xml files?
private void Validate(string path)
{
XmlValidatingReader valReader = null;
try
{
valReader = new XmlValueLengthValidatingReader(new StreamReader(path));
valReader.ValidationType = ValidationType.Schema;
// to validate according to schema, not defined in xml file
valReader.Schemas.Add(this.Schema);
//Set the validation event handler.
valReader.ValidationEventHandler += new ValidationEventHandler
(ValidationCallBack);
while (valReader.Read())
{
}
}
catch (XmlException e)
{
// not wellformed
}
finally
{
if (valReader != null)
valReader.Close();
}
}
private void ValidationCallBack (object sender, ValidationEventArgs args)
{
// not valid according to schema
}
Something like this?
Brecht
Martin Honnen - 30 Aug 2005 15:55 GMT
> XmlValidatingReader valReader = null;
> try
> {
> valReader = new XmlValueLengthValidatingReader(new StreamReader(path));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What is that? Should be XmlValidatingReader I guess.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Brecht Yperman - 30 Aug 2005 16:08 GMT
>> XmlValidatingReader valReader = null;
>> try
>> {
>> valReader = new XmlValueLengthValidatingReader(new StreamReader(path));
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> What is that? Should be XmlValidatingReader I guess.
Indeed. XmlValueLengthValidatingReader is an extension I made once to make
sure all attributevalues had no more than 50 chars.
Sorry 'bout that,
Brecht
Knighterrant - 31 Aug 2005 02:42 GMT
Thank you all!
Brecht Yperman 写道:
>
>
[quoted text clipped - 17 lines]
>
>
>I have created my schema format(xxx.xsd) for my xml files, but how can I
>use it validate my xml files?
Or, ofcourse:
<rootelement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="xxx.xsd">
</rootelement>