Want to read the specific report from the XML

XMLFile.xml (1.1 KB)

from the given XML i want to read second or third set of data. How i can do that?
in = XMLDoc.Element(“breakfast_menu”).Element(“food”).Elements
By using below flow i can able to read the first set of data

image

Can someone please help me on this.

1 Like

@vaibhav2.chavan
With the element function you will retrieve one element.

Give a try on
XMLDoc.Element(“breakfast_menu”).Elements(“food”)

Or XMLDoc.Root.descendants(“food”)

@ppr - Thanks for responding, i tried its working but in this case i can see all the records under food element but if i want to read particular element from 2nd or 3rd position how to do that?
e.g.
Berry-Berry Belgian Waffles
$8.95

Belgian waffles covered with assorted fresh berries and whipped cream

900

@vaibhav2.chavan
Lets step further one by one
A discrete Access can be done by using element Index e.g
XMLDoc.Element(“breakfast_menu”).Elements(“food”).tolist returning a list of xelement

And mylistvar.elementat(1) should Return the Second good element

Accessing a particular information Could be done Like mylistvar.elementat(1).element(“name”).value.tostring and should return the Name of the Second food element.

Thanks for clarification, i have used the expression - XMLDoc.Element(“breakfast_menu”).Elements(“food”).tolist returning a list of xelement
its giving me the list of elements.

but after that im not getting how to use it in for each.
Could you please help me to sort it out.

@vaibhav2.chavan
Please dont mixed Up lists and Elements

Your current flow iterates over all food Elements given by the Statement XMLDoc.Element(“breakfast_menu”).Elements(“food”).tolist

A discrete Access Like
mylistvar.elementat(1).element(“name”).value.tostring is returning the Second food element.

Here WE are using this within an assign Activity and assigning the Second food element to a variable of xelement Datatype. No Iteration ist Here needed on food element Base

Is IT more clear?

@ppr - I tried but getting below error.

mylistvar = XMLDoc.Element(“breakfast_menu”).Elements(“food”).tolist
SecondElement = mylistvar.elementat(1).element(“food”).value.tostring

@vaibhav2.chavan
The Datatype of mylistvar has to be list(of xelement)

@ppr - I ran it, now im getting error - emoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.

mylistvar = XMLDoc.Element(“breakfast_menu”).Elements(“food”).tolist
SecondElement = mylistvar.elementat(1).element(“food”).value.tostring

@vaibhav2.chavan
Should be only a small issue. In such cases the xaml should be Debugger and IT has to checked that the mylistvar is receiving the food element list.

@ppr - I checked in debug mode, the mylistvar is receiving null value. PFA xmal and xml file

@vaibhav2.chavan
Sorry im on Holiday without Laptop cannot Look your xamls. But IT Makes Sense. Empty list is Leading to null Reference

I am wondering why ITS now failing and Not earlier in your Runs. May crosscheck the Statement or give a try on XMLDoc.Root.descendants(“food”).toList

@ppr- checked but no luck same issue, no problem may be you can check once you back from holiday.

@vaibhav2.chavan
Sure ican doit on Weekend. But did you checked XMLDoc.Root.descendants(“food”).toList?

@ppr - i just changed the variable name from mylistvar to mylistvar1 it worked but when im displaying the SecondElement in message box im getting whole list as like output of mylistvar

@vaibhav2.chavan
Perfect WE have Progress. Can you Post the new statent from the Second element and the Output Here? Thanks

@ppr - sorry i didnt get, can you please elaborate

@vaibhav2.chavan
Sorry for my Cellphone Auto correction malfunction. Can you Post the Second Statement, that you are using for the secondelement and can you Post the output

@ppr - Second statement - mylist.ElementAt(1).Element(“food”).Value.ToString
The value is getting in second element is null

@vaibhav2.chavan
Can you confirm that mylist or mylist1 is Not empty

Then do you use the non empty listvar for the Second element retrieval?