Solved

i need to compare and validate my XML file with XSD file in windows forms using C#

Posted on 2009-04-04
2
280 Views
Last Modified: 2013-11-18
i need to compare and validate my XML file with XSD file in windows forms using C#
0
Comment
Question by:coventri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 24070103
Here is a simple example which you can build upon.
using System;
using System.Xml;
 
namespace XML_Validate
{
    class Program
    {
        static bool errFound = false;
 
        static void Main(string[] args)
        {
            XmlDocument xdoc = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings();
            XmlReader reader;
 
            settings.ValidationType = ValidationType.Schema;
            settings.Schemas.Add(null, @"C:\test.xsd");
            settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(validator_ValidationEventHandler);
 
            reader = XmlReader.Create(@"C:\test.xml", settings);
 
            try
            {
                xdoc.Load(reader);
            }
            catch (XmlException ex)
            {
                Console.WriteLine(ex.Message);
            }
 
            if (errFound)
            {
                Console.WriteLine("ERROR");
            }
            else
            {
                Console.WriteLine("No errors");
            }
 
            Console.ReadKey();
        }
 
        static void validator_ValidationEventHandler(object sender, System.Xml.Schema.ValidationEventArgs e)
        {
            errFound = true;
        }
    }
}

Open in new window

0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question