Reading XML Tag with Specific Attribute


I’m reading a value with this;

xdoc_XML.Descendants(cac+“AccountingSupplierParty”).Descendants(cac + “Party”).Descendants(cac + “PartyIdentification”).Descendants(cbc+ “ID”).FirstOrDefault().Value

But there’s a problem. There are three ID tags. Check below;

        <cbc:ID schemeID="xxx">Number1</cbc:ID>
    <cbc:ID schemeID="yyy">Number2</cbc:ID>
    <cbc:ID schemeID="zzz">Number3</cbc:ID>

When i use my code getting Number1 because of FirstorDefault.

But i need the part schemeID=“yyy” which is Number2 value. How can i get this?


I assume that you have setup correctly the namespaces and cac Varaible is e.g. on of them

give a try on:
xdoc_XML.Descendants(cac+“AccountingSupplierParty”).Descendants(cac + “Party”).Descendants(cac + “PartyIdentification”).Descendants(cbc+ “ID”).Where(Function (x) x.Attribute("schemeID").Value.Equals("yyy")).FirstOrDefault.Value

In case of it is not working please the complete xml file with us

1 Like

You are a LIFESAVER. Thank you so much. The best comment on this forum. Thank you so much Peter!

Thank you. In some cases XPATH Query are nice to handle and along with the namespace manage we can also handle name space.

In case of you are interested on this let me know along with a sample xml

Happy Automation :+1:

Please sir. I worked before with different xml format. Learned namespaces and this today. I will definetely look when I’m available. Good night :slight_smile:

Edit: I read your comment like “sample xaml” If you have a sample workflow like that can you share with me?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.