I am trying to read XML Value from a XML String. below is my Code: I want to read the value of the title tag: "503 Service Unavailable" Below XML is the response posted by Server -
string xmldata = "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>503 Service Unavailable</title>
</head><body>
<h1>Service Unavailable</h1>
<p>The server is temporarily unable to service your
request due to maintenance downtime or capacity
problems. Please try again later.</p>
</body></html>";
Code:
var rootElement = XElement.Parse(xmldata);
var errorTitle = rootElement.Element("title").Value;
I have tried this code as well :
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmldata);
string xPath = "html/head";
var nodes = xmlDoc.SelectNodes(xPath);
foreach (XmlNode childrenNode in nodes)
{
string item = childrenNode.InnerText;
}
Both pieces of code give me an error as - '>' is an unexpected token. The expected token is '"' or '''. Line 1, position 50.
Please suggest.