Select multiple xml tags and iterate

i have xml data of below type

i wan to iterate for every tag and capture the and tags.

appreciate your responses.

iterate every “a” tag and capture “b”, “c” tags and store in a variable

Hi there @bsamala

FIRST OPTION:

Here is a small snippet for your VB.NET code

Dim document As New XmlDocument()
document.Load(YourFile)
Dim nodelist As YourXmlNodeListAsOutArgument = 
document.SelectNodes("//YourMainNodeParentForAllNodes") 

Above snipped should have the correct dependency imports in the variables section (Check imports for an existing dependency)

  1. Have your xml file ready.
  2. Import dependency and replace/edit code as required for your convenience.
  3. Create an out argument that captures the IEnumerable list of nodes that comes out of the code snippet.
  4. Iterate through the nodes and check for the tags.

SECOND OPTION:

You can import the xml file and de-serialize it using an inbuilt activity (https://docs.uipath.com/activities/docs/deserialize-xml) and then iterate through it with either for-each loop or using a xpath expression (https://www.w3schools.com/xml/xml_xpath.asp).

Hope this helps :slight_smile:

Regards

1 Like

@bsamala in Case of you face any issues due the xml ist using namespaces have a Look Here

1 Like

Hi @Raghavendraprasad,

i haven’t tried with vb.net but gave a try with xpath expression. i used xpath expression activity and given string as input. but problem here is very first tag has url in it so it’s not accepting special character(for me it has thrown invalid special character “:” so i tried replacing with ascii values nothing helped). If you don’t mind can you get ne xpath expression for above xml? which has to iterate for every “a” tags and capture “b” and “c” tags.

@bsamala the : issue comes from the soap namespaces Name. In my xaml you can See a workaround with using the namespaces information. I would suggest to Analyse what is the Name of the a element (is IT with or without namespace) and maybe do the Combinaton of both (linq and xpath) Access methods

Well,

I don’t remember all the syntax either but here are a few common ones I ahve compiled a bit of trial and error should give you a precise result. And any schema that has special characters xpath doesn’t work properly (not an expert on why it doesn’t work or about inner workings/mechanism on how it is queried…) Hope this helps :slight_smile:

//*

selects all the elements in the document.

/descendant-or-self::node()

selects all elements, text nodes, processing instructions, comment nodes, and the root node / .

//text()

selects all text nodes in the document.

//comment()

selects all comment nodes in the document.

//processing-instruction()

selects all processing instructions in the document.

//@* 

selects all attribute nodes in the document.

//namespace::*

selects all namespace nodes in the document.

Finally, you can combine any of the above expressions using the union ( | ) operator.

Thus, I believe that the following expression really selects “all the nodes” of any XML document:

/descendant-or-self::node() | //@* | //namespace::*

Get back to me if xpath doesn’t work and we have to take the vb.net route and if the code supplied by me doesn’t work as expected :slight_smile:

Regards

PS : References : Stack overflow compilation. I haven’t personally tested every single one of the commands above except a few.