<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<meta name="Generator"/>
</head>
<body>
<h1>My head 1</h1>
</body>
</html>
This above is the .ToString of my XElement object , html. Looks good.
I am trying to get the body’s innerXml but my XPath returns null.
XElement html = GettheHTMLAsXElementCorrectly()
var whyIsThisNull = html.XPathSelectElement("/html/body");
Whenever namespaces are used (in your case in the
<html>) you need to define the namespace when searching for nodes:Using LINQ to XML
(In my opinion the easier and cleaner solution)
Using XPath
Update: Improved my answer as the example provided was not correct