XML Parsing node

I’m having problem getting the right relevance for a XML file that does not have a node. If the node exists, i can check for a value, but I’m unsure how to fail out if a node does not exists.

This works (with 3 or 1 in the id attribute) with the XML below:

exists( (child node of it) whose (node value of it =“done”) of select “status” of select “/change/computer” whose (attribute “id” of it as text = “3”) of xml document of file (“chg000099.xml”) )

It does not work if i look for a non-existing id … say 5
exists( (child node of it) whose (node value of it =“done”) of select “status” of select “/change/computer” whose (attribute “id” of it as text = “5”) of xml document of file (“chg000099.xml”) )

I get: Singular expression refers to nonexistent object.

XML file:

<?xml version="1.0" encoding="UTF-8"?>
<change number="chg000099">
  <computer id="1">
    <name>Server1</name>
    <status>waiting</status>
  </computer>
  <computer id="3">
    <name>Server3</name>
    <status>done</status>
  </computer>
</change>

Thank you for any help.

Try changing the singular “select” into plural “selects”

exists( (child nodes of it) whose (node value of it =“done”) of selects “status” of selects “/change/computer” whose (attribute “id” of it as text = “3”) of xml document of file (“chg000099.xml”) )

1 Like

You could also do this using xpaths

Q: exists xpaths "(change/computer[@id='3'][status='done'])" of xml documents of files "chg000099.xml"
A: True
T: 0.774 ms
I: singular boolean
1 Like

Thank you both! Exactly what i needed.