<?xml version="1.0" encoding="UTF-8"?>
Everyday Italian
Giada De Laurentiis
2005
30.00
Harry Potter
J K. Rowling
2005
29.99
XQuery Kick Start
James McGovern
Per Bothner
Kurt Cagle
James Linn
Vaidyanathan Nagarajan
2003
49.99
Learning XML
Erik T. Ray
2003
39.95
how to get specific like ->book category=“children” , in that ->author name ?
This will return the author name from the book whose category is children.
Note: The text shared in the question doesn’t show the XML tags such as <book>, <author>, etc. Please make sure the actual .txt file contains valid XML before using XDocument.Parse().
UiPath provides a set of XML activities to read and query XML data. You can use Deserialize XML and then use an XPath expression to retrieve the required node.
one small thing worth adding for robustness, the final expression dropped the ?. that was in Mayuresh’s first answer (x.Attribute(“category”).Value instead of x.Attribute(“category”)?.Value). If any book element in your real file doesnt have a category attribute at all, that line throws a NullReferenceException instead of just skipping it. Worth putting the ?. back just in case your production xml isnt as clean as this sample
also if you ever need more than one book matching (say two “children” books), swap FirstOrDefault() for ToList() and authorname becomes a List(Of String) instead of a plain String, since right now you’ll only ever get the first match.