Counting Items from an XML

Hello team,

I am having trouble finding logic to count a number of items in an XML.

This is a sample of an XML. What I need to know is how many “det nItem” are in XML. Note: This amount is variable. I tried using Xpath, Get XML Nodes, .Element. Well, I don’t know if I’m using it the wrong way, but none of them worked for what I need

Can someone help me

Hi @KMota
From the output that components create you can do your thing!
This might be helpful to you Please see the link for your reference.

https://go.uipath.com/component/xml-conversion-activities

cheers :smiley:

Happy learning :smiley:

1 Like

Hi,

You can get it using Deserialize XML Activity in UiPath.Web.Activities package.
The following steps shows how to get the number of “<det nitem=” under root element.

  1. Read your xml as string, and parse it by Deserialize XML activity as xDocument (xDoc).

  2. Get root element (xRoot=xDoc.Root) and its namespace (xNS=XRoot.Name.Namespace).

  3. Get descendants which name is “det”.
    elementsDet = xRoot.Descendants(xNS+"det")

  4. Get number of det element which has nItem attribute.
    count = xElementsDet.Count(function(x) x.Attributes("nItem").Count>0)

I’ll attach the following sample.

Sample20191109.zip (15.5 KB)

Regards,

1 Like

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