I've had several other question related to the subject:
getting a parent node and its child, where the child has a certain text
and XPath finding certain node with certain text
Lets say this is my HTML:
<body>
<div>
<span>something else</span>
<span>something</span>
<span>something else</span>
<div>
</body>
I am using the following to query for a node with certain text:
$node_with_value = $xpath->query('(//*[text()= "'something"])');
this returns the list with all node that has something. In this case it will be only 1.
to find its parent i do:
parent = $node_with_value->item(0)->parentNode;
Now my question is how can i check what number of child it is.
in the above we have 3 span children to the div, counting from top to bottom its number 2. is there a way to count that programmaticaly?