Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / August 2005

Tip: Looking for answers? Try searching our database.

How to use schema validate xml file?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Knighterrant - 30 Aug 2005 09:07 GMT
I have created my schema format(xxx.xsd) for my xml files, but how can I
use it validate my xml files?
Brecht Yperman - 30 Aug 2005 15:29 GMT
>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]
>
>  
Brecht Yperman - 30 Aug 2005 15:32 GMT
>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>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.