XML DTD Validation

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi All,
I hv written following code for the XML validation with a given DTD .
<div style="background-color:white; color:black
<pre><span style="color:blue private <span style="color:blue void btnValidate_Click(<span style="color:blue object sender, EventArgs e)





{



XmlTextReader r = <span style="color:blue new XmlTextReader(<span style="color:#a31515 "D:\Downloads\100036.xml");



XmlValidatingReader v = <span style="color:blue new XmlValidatingReader(r);



v.ValidationType = ValidationType.DTD;



v.ValidationEventHandler += <span style="color:blue new ValidationEventHandler(v_ValidationEventHandler);



<span style="color:blue while (v.Read())

{

<span style="color:green // Can add code here to process the content.

}



v.Close();



<span style="color:green // Check whether the document is valid or invalid.

<span style="color:blue if (isValid)

MessageBox.Show(<span style="color:#a31515 "Document is valid");

<span style="color:blue else

MessageBox.Show(<span style="color:#a31515 "Document is invalid");

}





<span style="color:blue void v_ValidationEventHandler(<span style="color:blue object sender, ValidationEventArgs e)

{

isValid = <span style="color:blue false;

MessageBox.Show(e.ToString());



MessageBox.Show(e.Exception.ToString());



}

[/code]

Here, its assumed that the XML file contains DTD path embedded in it already.
But, I want to pass the DTD path-location @ runtime. <span style="font-family:Arial; font-size:x-small
I dont have the DOCTYPE declaration in my XML .How to do this?
Thanks in advance..
<
alex<br/>
<br/>
<br/>

View the full article
 
Back
Top