all groups > dotnet xml > august 2005 >
You're in the

dotnet xml

group:

How to use schema validate xml file?


How to use schema validate xml file? Knighterrant
8/30/2005 4:07:47 PM
dotnet xml: I have created my schema format(xxx.xsd) for my xml files, but how can I
Re: How to use schema validate xml file? Brecht Yperman
8/30/2005 4:29:45 PM

[quoted text, click to view]

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

Re: How to use schema validate xml file? Brecht Yperman
8/30/2005 4:33:18 PM

[quoted text, click to view]

Or, ofcourse:

<rootelement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="xxx.xsd">
</rootelement>

Re: How to use schema validate xml file? Martin Honnen
8/30/2005 4:55:12 PM


[quoted text, click to view]


[quoted text, click to view]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What is that? Should be XmlValidatingReader I guess.

--

Martin Honnen --- MVP XML
Re: How to use schema validate xml file? Brecht Yperman
8/30/2005 5:08:39 PM

[quoted text, click to view]

Indeed. XmlValueLengthValidatingReader is an extension I made once to make
sure all attributevalues had no more than 50 chars.

Sorry 'bout that,
Brecht

Re: How to use schema validate xml file? Knighterrant
8/31/2005 12:00:00 AM
Thank you all!


Brecht Yperman дµÀ:

[quoted text, click to view]
AddThis Social Bookmark Button