How to check if XML element exist

How do you check if an node/element exist in a XML? I want to get the value of a specific element in the XML.

I created a sequence where it

  1. Read the Xml file
  2. Desterilize the XML (output is XML_Nodes)
  3. how to check if element exist? i.e check if element ABC exist
  4. if element exist, get the value.
    XML_Nodes.Element(“Application”).Element(“Loan”).Elements(“Data”).Elements(“ABC”).ToString

Sample XML

<-Application>
<-Loan>
<-Data>
<-ABC>
<-EFG>
<-/Data>
<-/Loan>
<-/Application>

@happygal321

as a quick shot give a try on
YourXDocVar.Root.Descendants(“ABC”).ToList.Count > 0
it will indicate if 1 or more ABC elements are available or not

Sometimes the XML has multiple “ABC” but under different nodes. I want to see if it exist under the specific nodes Application-Loan-Data-ABC

i.e.
<-Application>
<-Loan>
<-Data>
<-EFG>
<-/Data>
<-Data2>
<-ABC>
<-/Data2>
<-/Loan>
<-/Application>

@happygal321
find some starter help here:
HasSpecificElements_InSpecificPath.xaml (7.4 KB)
working with:
data.xml (271 Bytes)

Ensure for working demo4 case
xDoc.XPathSelectElements("/Application/Loan/Data4/ABC").toList
following import:
grafik

Thanks!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.