I need to extract the vaxTimestamp and vaxDocId. If I loop through all the element of the XML file I can see they are of the type Processing Instructions.
Thanks - but I’d rather avoid using RegEx now that it is an element that somehow can be referenced. I can use xmlDoc.FirstNode.ToString as well - but I’d like to be able to use the name/ID of the processing instruction instead like I do with all the other nodes/elements.
@jacchr
having a sample string, parsing it to a xDocument with the help of Deserialize XML Activity (Package UiPath.WebAPI.Activities) has following result:
@jacchr
the base type for LINQ is the IEnumerable. Have a look here:
@Dave gave us a good explanation on what it is here:
The nature of Where is returning us an IEnumerable(Of T) (just simplified) and can contain:
0
1
multiple
Items
So we have to ensure in your case, that we catch the data from 1 and only one element (think on no filter return and/or multiple catches).
For this we can work with DefaultIfEmpty and mixing Method and Query Syntax:
(From pi In xDoc.Nodes().Where(Function (x) x.NodeType = XmlNodeType.ProcessingInstruction).Cast(Of XProcessingInstruction)
Where pi.Target.Equals(PIFilterKey)
Select pi).DefaultIfEmpty(New XProcessingInstruction("NoName","UNDEFINED")).First().Data
line1: fetch all PIs
line2: Filter all PIs with the name equal to the FilterKey
line3: for an empty result return a dummy PI, other wise return the found PIs, from this take the first PI and its Data
In case of we would expect multiple PI as a filer result we would return it e.g. as List/Array and process / evaluate later.