Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-04
2
Medium Priority
?
282 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

688 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