views:

94

answers:

2

i have one default.xml file where i am storing all default values.suppose if invalid file with the same default.xml name exists i have to display message in the status bar.

A: 

You need to create a schema (XSD) for your XML.

Then you can use something like the validator pranay_stacker links to check that an XML file is in the correct format for your application.

Microsoft have an XML Schema Definition Tool (Xsd.exe)

This can be used to convert XML to XSD. Having done this with your reference XML file, you can then use the XSD to validate any future XML files you read.

ChrisF
+1  A: 

Create a XSD for the schema you want in the XML...then any xml you have can be validated against the XSD in the below way

public static ArrayList VerifyXML(string xmlFile, string XSDFilepath)
    {
        XmlDocument xDoc = new XmlDocument();
        xDoc.Load(xmlFile);
        xDoc.Schemas.Add("Mention your target namespace here", XSDFilepath);
        xDoc.Validate(new ValidationEventHandler(ValidationCallBack)); 
        return m_oResults;
    }
 private static void ValidationCallBack(Object sender, ValidationEventArgs e)
    {
        switch (e.Severity)
        {
            case XmlSeverityType.Error:
                m_oResults.Add(e);
                break;
            case XmlSeverityType.Warning:
                m_oResults.Add(e);
                break;
        }
    }

So you will get the list of errors and warnings..

srivatsayb