Need help on XML parser in Ranorex
Posted: Mon Dec 08, 2014 12:58 pm
Hi,
I am getting a REST api XML response. I am storing the response in string format. Now I want to parse the xml and get some node values. Could you please help me in the code?
this fetches the response
String response = client.MakeRequest();
Now I want to parse the response, so I am using following code
string hoursworked = testxml.Parser(response);
parser function is as follows
public string Parser(string res)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(res);
XmlNodeList nodeList = doc.DocumentElement.SelectNodes("/AttLeaveDetails/AttendanceList/SelfAttendanceDetails");
string hrwrkd = "",reqdhrs="";
Report.Log(ReportLevel.Info, "xml request generated is"+doc);
foreach (XmlNode node in nodeList)
{
hrwrkd = node.SelectSingleNode("HoursWorked").InnerText;
reqdhrs = node.SelectSingleNode("RequiredHours").InnerText;
Report.Log(ReportLevel.Info,"hours worked is" + hrwrkd);
Report.Log(ReportLevel.Info,"required hours is" + reqdhrs);
}
return hrwrkd;
however when I run it, it seems the xml response is not properly converted from string to xml and due to this I am not able to parse it. Could you please provide help on it?
}
I am getting a REST api XML response. I am storing the response in string format. Now I want to parse the xml and get some node values. Could you please help me in the code?
this fetches the response
String response = client.MakeRequest();
Now I want to parse the response, so I am using following code
string hoursworked = testxml.Parser(response);
parser function is as follows
public string Parser(string res)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(res);
XmlNodeList nodeList = doc.DocumentElement.SelectNodes("/AttLeaveDetails/AttendanceList/SelfAttendanceDetails");
string hrwrkd = "",reqdhrs="";
Report.Log(ReportLevel.Info, "xml request generated is"+doc);
foreach (XmlNode node in nodeList)
{
hrwrkd = node.SelectSingleNode("HoursWorked").InnerText;
reqdhrs = node.SelectSingleNode("RequiredHours").InnerText;
Report.Log(ReportLevel.Info,"hours worked is" + hrwrkd);
Report.Log(ReportLevel.Info,"required hours is" + reqdhrs);
}
return hrwrkd;
however when I run it, it seems the xml response is not properly converted from string to xml and due to this I am not able to parse it. Could you please provide help on it?
}