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.

cheers :smiley:

Happy learning :smiley:

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,