So I have this:
<Presentation>
<Info attr1="red" attr2="blah"/>
<Info attr1="big" attr2="iasjd"/>
<Info attr1="funky" attr2="asf"/>
...
<Info attr1="damn" attr2"..."/>
</Presentation>
How can I check if a node exists, that has value of attr1
as funky
, i.e.? I can do that by checking if the returned string in my code is empty, or by using count
Xpath function to check if it returns 0, but is there some other function (or way) to check if that certain node with that certain attribute exists. Some more elegant way?
Example: As I can have the case:
<Presentation>
<Info attr1="red" attr2="blah"/>
<Info attr1="big" attr2="iasjd"/>
...
<Info attr1="damn" attr2"..."/>
</Presentation>
And as I don't have the node with attribute value funky
- I do some other stuff in my code.
UPDATE:
I am doing that in PHP. I need to check what is the value of this attr1 as string. So first I want to check if there is an Info
node, where the attr1 value is exactly "funky". If yes - then do some logic in PHP. If not - then do some other stuff (in PHP). I am using the function xpath() on a SimpleXMLElement object, so I get the result as an array. The xpath() function is made so if the XPath expression doesn't work, a boolean(false) is returned, instead of an array. But that is not a safe enough check in my case.