XML xpaths question

(imported topic written by cstoneba)

I’m trying to retrieve the value of the “state” node for nodes with an “ip” attribute of “1.2.3.4”. But I can’t seem to get the “node value” querey to work when using “xpaths” inspector.

q: node value of child node 2 of xpaths “/result/pool/member” whose (node value of attribute “ip” of it = “1.2.3.4”) of xml document of file “C:\status.xml”

E: The expression could not be evaluated: Windows Error 80020005: Type mismatch.

The pool is available

Pool member is available

ENABLED

ENABLED

UP

Pool member is available

ENABLED

ENABLED

UP

Pool member is available

ENABLED

ENABLED

UP

(imported comment written by jeremylam)

the "attribute of " apparently returns an xml dom node, not a string:

q: (attribute “ip” of it) of xpaths “/result/pool/member” whose (exists attribute “ip” of it) of xml document of file “C:\status.xml”

E: This expression evaluates to an unrepresentable object of type “xml dom node”

So you can cast it to a string (using the “as text” inspector) and compare:

q: (it as xml) of xpaths “/result/pool/member” whose (attribute “ip” of it as text = “1.2.3.4”) of xml document of file “C:\status.xml”

A: %0d%0a%09Pool member is available%0d%0a%09ENABLED2%0d%0a%09ENABLED%0d%0a%09UP%0d%0a

q: (child node 2 of it as text) of xpaths “/result/pool/member” whose (attribute “ip” of it as text = “1.2.3.4”) of xml document of file “C:\status.xml”

A: ENABLED

or just use 100% xpath, which is much cleaner:

q: (it as text) of xpaths “/result/pool/member/state” of xml document of file “C:\status.xml”

A: ENABLED

(imported comment written by jeremylam)

Forum markup ate the xpath, trying again:

q: (it as text) of xpaths "/result/pool/member[@ip='1.2.3.4']/state" of xml document of file "C:\status.xml"

(imported comment written by jeremylam)

And because it was confusing me also: node type only works on specific types of nodes - I guess only text and attribute nodes.

The following:

<state>ENABLED</state>

Is actually a node that contains a text node that contains “Enabled”.

This might illustrate the structure:

q: (node type of it) of xpaths “/result/pool/member/state” of xml document of file “C:\status.xml”

A: 1

T: 0.450 ms

I: plural integer

q: (node value of it) of xpaths “/result/pool/member/state” of xml document of file “C:\status.xml”

E: The expression could not be evaluated: Windows Error: Type mismatch.

q: (node type of child node of it) of xpaths “/result/pool/member/state” of xml document of file “C:\status.xml”

A: 3

T: 1.026 ms

I: plural integer

q: (node value of child node of it) of xpaths “/result/pool/member/state” of xml document of file “C:\status.xml”

A: ENABLED

T: 1.098 ms

I: plural string

(imported comment written by cstoneba)

code

q: (it as text) of xpaths “/result/pool/member/state” of xml document of file “C:\status.xml”{code}

this is perfect jeremylam, and it’s very efficient too. thanks!

(imported comment written by cstoneba)

now how would I put in session relevance to replace the IP addr? The following gives me a relevance substitution error.

(it as text as lowercase = “enabled”) of xpaths “/result/pool/member/state” of xml document of file (parent folder of regapp “BESClient.exe” as string & “__BESData\actionsite\status-qae.xml”)

(imported comment written by cstoneba)

correction, this is the code that is giving me the problem:

(it as text as lowercase = “enabled”) of xpaths “/result/pool/member/state” of xml document of file (parent folder of regapp “BESClient.exe” as string & “__BESData\actionsite\status-qae.xml”)

(imported comment written by cstoneba)

(it as text as lowercase =  "enabled") of xpaths "/result/pool/member[@ip='{addresses whose (it as string != "0.0.0.0") of ip interfaces whose (not loopback of it) of network}']/state" of xml document of file  (parent folder of regapp "BESClient.exe" as string & "\__BESData\actionsite\status-qae.xml")

(imported comment written by cstoneba)

can anyone tell me how to add the IP Managed Property in place of the IP ?

(imported comment written by jeremylam)

can anyone tell me how to add the IP Managed Property in place of the IP ?

You’ll have to construct a valid XPath query - and accounting for the plurals. XPath uses the format “@ip=’…’ or @ip=’…’” so I can get the entire query here:

q: "/result/pool/member[" & concatenation " or " of (("@ip='" & it as string & "'") of addresses whose (it as string != "0.0.0.0") of ip interfaces whose (not loopback of it) of network) & "]/state"
A: /result/pool/member[@ip='192.168.84.203' or @ip='192.168.106.117']/state

And then inserted back into your original statement:

(it as text as lowercase = "enabled") of xpaths ("/result/pool/member[" & concatenation " or " of (("@ip='" & it as string & "'") of addresses whose (it as string != "0.0.0.0") of ip interfaces whose (not loopback of it) of network) & "]/state") of xml document of file "C:\status.xml"

(imported comment written by cstoneba)

how would I replace the IP of “1.2.3.4” with session relevance of an IP Managed Property?

confinue if {(it as text as lowercase =  "enabled") of xpaths "/result/pool/member[@ip='1.2.3.4']/status" of xml document of file  "c:\users\desktop\test.xml"}

(imported comment written by SystemAdmin)

Thank you all, we had been looking for better part of two months and found this thread. It has been a life saver. Thank you again.