Closed
How to fetch XML data with 'select single node'?
I want to fetch the highlighted field in the image.
On selectSingleNode's xpath, how do I define a name space?
This content is closed to future replies and is no longer being maintained or updated.
Links may no longer function. If you have a similar request, please write a new post.
I want to fetch the highlighted field in the image.
On selectSingleNode's xpath, how do I define a name space?
Provide namespace values in xpath string only.
I already tried, and it says that the name space is not defined.
Try with below code.
var xmlDoc = new XmlDocument();
xmlDoc.Load(@"filename");
var namespaceName = "ns";
var namespacePrefix = string.Empty;
XmlNamespaceManager nameSpaceManager = null;
XmlNodeList nodeList = xmlDoc.SelectNodes(string.Format("/{0}fileresponse/{0}data/{0}folder/{0}pages", namespacePrefix), nameSpaceManager);
if (nodeList != null)
{
foreach (XmlNode childNode in nodeList)
{
string first = childNode.ChildNodes[0].ChildNodes[1].ChildNodes[1].InnerText;
}
}
below is sample xml:
<fileresponse>
<data>
<filename>abc</filename>
<filetype>1</filetype>
<folder>
<name>pega</name>
<documentid>123</documentid>
<pages>
<NS1:Page xmlns:NS1="http://b.ws">
<NS1:Deleted>yes</NS1:Deleted>
<NS1:Id>
<NS1:Id>3131231232</NS1:Id>
<NS1:RefId>12refid</NS1:RefId>
</NS1:Id>
<NS1:PageNumber>1</NS1:PageNumber>
</NS1:Page>
</pages>
</folder>
</data>
</fileresponse>
Hi Jayachandra,
Thanks for the work-around I'll check and confirm.
I was just wondering why can't I use 'select single node' method since xpath can handle namespaces as well. Could it be a limitation of the method?
I have another question.
I gave my XPath as '/FileResponse/Data/folder[3]/Subfolder[1]/Pages/page[1]/RefId' on select single node method.
It's not returning the value.
Question Solved
Question Solved
Question
Question
Question
Question Solved
Question
Question Solved
Question
Discussion
Pega Collaboration Center has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.