Grab decendant from XML-file

I have a XML file with a structure like this:

<cac:LegalMonetaryTotal>

<cbc:LineExtensionAmount currencyID=“NOK”>360.42</cbc:LineExtensionAmount>
<cbc:TaxExclusiveAmount currencyID=“NOK”>360.42</cbc:TaxExclusiveAmount>
<cbc:TaxInclusiveAmount currencyID=“NOK”>438.28</cbc:TaxInclusiveAmount>
<cbc:PayableAmount currencyID=“NOK”>438.28</cbc:PayableAmount>

How can I grab the LineExtensionAmount? I have tried the following (cannot share the entire workflow because it contains lots of sensitive stuff):

For each with: For each Item in xmlDoc.Descendants(cac+“LegalMonetaryTotal”)
with in the previous for each: For each iline in item.Descendants(cac+“LegalMonetaryTotal”)
Then within that loop: iline.Descendants(cbc+“TaxExclusiveAmount”).Value.Replace(“.00”,“”).ToString

This however, just returns blank values. It works when it’s another field three levels deep, like this:

 <cac:TaxTotal>

<cbc:TaxAmount currencyID=“NOK”>77.86</cbc:TaxAmount>

  • cac:TaxSubtotal
    <cbc:TaxableAmount currencyID=“NOK”>49.00</cbc:TaxableAmount>

If I change the first for each to TaxTotal, the second to TaxSubtotal and the assign (third) to TaxableAmount, it works. The same code doesn’t work with two levels. Any ideas?

Never mind, I solved it myself :slight_smile: