andnesper
(Andreas Persson)
March 27, 2018, 7:47am
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?
vivek_shiv
(Vivek Shivankar)
April 10, 2018, 7:15am
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
Ananthu
(Ananthakrishnan K)
June 27, 2018, 7:41pm
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
andnesper
(Andreas Persson)
June 27, 2018, 9:11pm
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
Ananthu
(Ananthakrishnan K)
June 28, 2018, 4:40am
5
Hi,
Thanks for your help . 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
andnesper
(Andreas Persson)
June 28, 2018, 7:41am
6
Did you try to change the “cac” to one ssdh for example?
See if this could help:
Hello, try to use “{ }” or if it’s dynamic which is like, “is dynamic ”
<ab:xlvalue>Str</ab:xlvalue>
XNamespace ab = "http://your-url";
XElement tempElement = doc.Descendants(ab + "xlvalue").FirstOrDefault();
this way it will look for an xmlns:ab=… section in your document to find out which namespace URI “ab” refers to.
You can get it by finding the attribute value for XNamespace.Xmlns + “ab”
let us knwo if this is the answer you are looking for
The UiPath Documentation Portal - the home of all our valuable information. Find here everything you need to guide you in your automation journey in the UiPath ecosystem, from complex installation guides to quick tutorials, to practical business...
2 Likes
Ananthu
(Ananthakrishnan K)
June 29, 2018, 5:56am
7
Thanks Andrew! It worked.
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
andnesper
(Andreas Persson)
July 2, 2018, 7:29am
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?
1 Like
Ananthu
(Ananthakrishnan K)
July 2, 2018, 8:04am
9
Hi Andrew!
I got it resolved. Thanks
Regards,
Ananthu
2 Likes
andnesper
(Andreas Persson)
July 2, 2018, 9:19am
10
Great! Could you share how you did it?
1 Like
Ananthu
(Ananthakrishnan K)
July 3, 2018, 1:33pm
11
Ya sure Andrew! Will send it later tonight.
Regards,
Ananthu
1 Like
Ananthu
(Ananthakrishnan K)
July 8, 2018, 7:22am
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.
Looping multiple xml tags.xaml (7.4 KB)
Thanks and regards,
Ananthu