I have a XML file, I want to extract its components.
Is there a way to do it?
Thanks in advance,
Hi @xcj81688
Welcome to our community!
there are many post about that in the forum, please go through all the solutions provided to people, if any specific question come here, for now please check this guide
Regards
HI,
FYI, basically as the following.
First, install WebApi activites package
then Read text, deserialize xml string to XDocument. Finally extract necessary information from it.
Regards,
Hi @xcj81688 Please check the below link
If it didn’t help, please share the input file and let us know what are the components you need from an XML
Hi @xcj81688
- Drag a “Read Text File” In the “File name” property, enter the path to the XML file , Set the “Output” property to a variable of type “String” that will hold the contents of the XML file.
- use “Invoke Code” activity, its properties, set the “Language” property to “VB.Net”., In the “Code” property, enter the following code:
Dim xmlDoc As New System.Xml.XmlDocument()
xmlDoc.LoadXml(fileContents)
Dim components As System.Xml.XmlNodeList = xmlDoc.SelectNodes("//components/component")
For Each component As System.Xml.XmlNode In components
Dim name As String = component.Attributes("name").Value
Dim type As String = component.SelectSingleNode("type").InnerText
Dim value As String = component.SelectSingleNode("value").InnerText
' Do something with the extracted data
Next
In this example, we first read the contents of the XML file into a string variable using the “Read Text File” activity. We then use the “Invoke Code” activity to execute VB.NET code that creates an XmlDocument
object, loads the XML file contents, and extracts the components using the SelectNodes
and SelectSingleNode
methods. Finally, we use the extracted data within the For Each
loop.
Note that you will need to adjust the code to match the structure of your own XML file.