I have an string, and I want to do some things with it if it is a valid XML; and If not, tell the user that the string is not a valid XML.
My code is this:
try
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(rawData);
//And here I want to do some things with doc if it is a valid XML.
}
catch
{
//Tell the user that the string is not a valid XML.
}
Now, If rawData
contains a valid XML data, there is no problem. Also if rawData
contains something else (like HELLOEVERYBODY!
), It will throw an exception, So I can tell the user the string is not a valid XML.
But When rawData
contains a HTML page, The process takes a long time (more than 20 seconds!)...
It may differ from page to page. for example, it can process stackoverflow.com
quickly, but processing 1pezeshk.com
takes a long long time...
Isn't there any faster way to validate XML before loading it into a XmlDocument
?