C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » XML »

Validate an XML against Schema


Posted Date: 17 Nov 2008    Resource Type: Code Snippets    Category: XML
Author: Deepika HaridasMember Level: Diamond    
Rating: 1 out of 5Points: 10



Simple method that would validate your XML against the Schema.


public static void validatexml(String str)
{
XmlValidatingReader validate= null;
//URL of path containing XML data
XmlTextReader xRead = new XmlTextReader(str); //Load selected document
validate = new XmlValidatingReader(xRead); //Validate xmlreader
validate.ValidationType = ValidationType.Schema; //Validate Schema of loaded xml file
validate.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);

try
{
while (validate.Read())
{ }
if (m_valid)
{
MessageBox.Show("Valid documnent");
m_valid = true;
}
}
catch
{
MessageBox.Show("Incorrect file or XML document not well formed");
}

validate.Close();
}

public static void ValidationCallBack(object sender,ValidationEventArgs args)
{
MessageBox.Show("Validation error :" + args.Message);
m_valid = false;
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Validate XML  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Generate XML Response
Previous Resource: Importing XML Into a Recordset
Return to Discussion Resource Index
Post New Resource
Category: XML


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use