Trying to parse xml, but xmldocument.loadxml() is trying to download?

Posted by maxp on Stack Overflow See other posts from Stack Overflow or by maxp
Published on 2010-03-17T22:46:29Z Indexed on 2010/03/17 22:51 UTC
Read the original article Hit count: 310

Filed under:
|
|

I have a string input that i do not know whether or not is valid xml.

I think the simplest aprroach is to wrap

new XmlDocument().LoadXml(strINPUT);

In a try/catch.

The problem im facing is, sometimes strINPUT is an html file, if the header of this file contains

<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
<html xml:lang=""en-GB"" xmlns=""http://www.w3.org/1999/xhtml"" lang=""en-GB"">

...like many do, it actually tries to make a connection to the w3.org url, which i really dont want it doing.

Anyone know if its possible to just parse the string without trying to be clever and checking external urls? Failing that is there an alternative to xmldocument?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about c#