Read XML files and get data - Namespaces

activities
xml

#1

I’m trying to read several XML invoices to extract data. I have done as the XML instruction from UiPath explain. Every line of my XML invoice starts with cbc: or cac: and i use the “Descendants” to reach the Namespaces, but in the Output I’m getting nothing, it is just empty.

Anyone know why this happend?

image

image


#2

Hi,

Can you change Element() to Elements() if there are multiple xml tag.
Try to reach the exact value basis on xml tag name.

If it not work please share your program, Will work on it.

Thanks


#3

Hi Andnesper,
Could you just explain how to use descendants in XML to reach a name space? I have a similar requirement.

Thanks and regards
Ananthu


#4

Hello,

You could try this:

cac = “urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2”

cec=“urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2”

cbc=“urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2”

Then refer to the line you want:

netAmount= xmlDoc.Descendants(cac+“LegalMonetaryTotal”).Descendants(cbc+“TaxExclusiveAmount”).FirstOrDefault().Value

“LegalMonetaryTotal” is the area where you want to pick the value/text from. While “TaxExclusiveAmount” will be the specific line.

Hope this was to some help :slight_smile:


#5

Hi,
Thanks for your help :slight_smile:. But, it’s still throwing an error. I have attached the error screen shot for you reference. Kindly let me know if you have an alternate solution.

My xml files contains tags in the below format.
tns:xxxx
ssdh:yyyy
ssdh:zzzz
ssdh:wwww
Value
ssdh:wwww
ssdh:zzzz
ssdh:yyyy
tns:xxxx

I have to retrieve the value and print it in a message box.

Thanks and regards,
Ananthu
IMG_20180628_100840_875|690x323


#6

Did you try to change the “cac” to one ssdh for example?

See if this could help:


#7

Thanks Andrew! It worked. :slight_smile:

Do you know how to access the fourth or third recurrence of a descendant and extract it’s values?

Like, instead of FirstorDefault() is there any function to access the second or third occurrence of that particular descendant…

Thanks and regards,
Ananthu


#8

I’m not sure. I struggle with the same issue right now.

Do you have any reference in the XML file that you could use?


#9

Hi Andrew!
I got it resolved. Thanks :slight_smile:

Regards,
Ananthu


#10

Great! Could you share how you did it? :slight_smile:


#11

Ya sure Andrew! Will send it later tonight.:slight_smile:

Regards,
Ananthu


#12

Hey Andrew,
Sorry for the delay ! I got caught up with some work. I have attached my workflow. Kindly let me know if you need any help.:slight_smile:
Looping multiple xml tags.xaml (7.4 KB)

Thanks and regards,
Ananthu