I have a nested loop in the SOAP response and I want to read the lowest level value from the loop. How can I write a recursive logic in C# to do the same? Below is my sample SOAP request
<hierarchy>
<company company_id="ABC" name="ABC">
<company company_id="DEF" name="DEF">
<company company_id="1234" name="1234">
<company company_id="5678" name="5678">
<company company_id="1000" name="1000">
</company>
</company>
</company>
</company>
</company>
</hierarchy>
I wanted to write a logic which is something like if company does not have anymore child nodes then read that value. FYI, this nested loop is dynamic meaning some SOAP response can have 5 nested companies and some can have 3.
Thank you for your help in advance.
Something like this? If I understood your problem correctly.
public void foo(XmlNode node)
{
if (node.HasChildNodes)
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
foo(node.ChildNodes[i]);
}
}
else
{
//read value
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.