I have an XML file that I am currently working on where the total number of records is provided at the end of the file in the following format:
I am currently following these steps:
- Read in XML in Text File activity
- Deserialize XML
- Get XML Nodes
- For Each checking if item.Name.LocalName = “trailer”
Unfortunately this only returns a blank value. Any ideas on how to get that 14 out?
Often namespaces, other issues are leading to empty results. We worked heavily on such issues got it more and more under control. So I have following suggestions:
- do a debug with breakpoints and check what is the result Step 3, verify that “trailer” is accepted as element name/localname. Otherwise printout element names and check out what is expected.
the 14 should be retrieved from Attribute totalRecords, due trailer is a so called empty element
Other option would be share the xml or demo data xml (but with all same settings e.g namespace definitions) so I can check the particular cases at my IMPs and share some code parts if there are matching to your needs
If you only need that from the xml, change your step 2 into a string manipulation like shown here: String.Substring Method (System) | Microsoft Learn
If there is only one occurrence of tag present in your xml file then I recommend to use Regex expression.
Read xml file into a string strXML
resultString = Regex.Match(strXML, strPattern).ToString //parse the string to integer if required
You need to retrieve the attribute value not the element value (sorry for confusing you ).
Check this screenshot and make sure you have changed the item type in for each activity to xelement