I am new C#. I make a SOAP request and in the SOAP response, I need to access repeating nodes 'ABC'. This is how my SOAP Response looks like:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<work:WorkContext xmlns:work="http://example.com/soap/workarea/">sdhjasdajsdhj=</work:WorkContext>
</env:Header>
<env:Body>
<ReadABCResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.xyz.com/abc/a6/AB/XYZ/V1">
<ABC xmlns="http://xmlns.xyz.example/abc/a6/AB/XYZ/V1">
<asd xmlns="http://xmlns.example.com/abc/a6/AB/XYZ/V1" xsi:nil="true"/>
<xyz xmlns="http://xmlns.example.com/abc/a6/AB/XYZ/V1" xsi:nil="true"/>
</ABC>
<ABC xmlns="http://xmlns.example.com/abc/a6/AB/XYZ/V1">
<asd xmlns="http://xmlns.example.com/abc/a6/AB/XYZ/V1" xsi:nil="true"/>
<xyz xmlns="http://xmlns.example.com/abc/a6/AB/XYZ/V1" xsi:nil="true"/>
</ABC>
</ReadABCResponse>
</env:Body>
</env:Envelope>
My code is as below:
XmlDocument responseDoc = new XmlDocument();
responseDoc.LoadXml(responseString); //responseString is set to above SOAP response.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(responseDoc.NameTable);
nsmgr.AddNamespace("env", "http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("work", "http://example.com/soap/workarea/");
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
nsmgr.AddNamespace("", "http://xmlns.example.com/abc/a6/AB/XYZ/V1");
XmlNodeList lst = responseDoc.SelectNodes("/env:Envelope/env:Body/ReadABCResponse/ABC", nsmgr);
Console.WriteLine("Count " + lst.Count);
// and then iterate over the repeating ABC nodes to do some work.
However value of Count is always printed as 0. I have tried different combinations of the xpath path in "SelectNodes" method including "//ABC" - which I thought should give me all the repeating 'ABC' nodes but it does not.
What is wrong with my code. please can someone highlight and help me!
I have looked around on this site but cant figure out what is wrong with this code.