I am trying to parse a HTML document with help of DOM Xpath
I have several input tags in the HTML such as
<form id="someid" action="login.jsf">
<input type="hidden" id="someid" name="somename" value="somevalue">
<input type="text" id="someid" name="somename" value="somevalue">
</form>
I have following code to reach the all the input tags inside form.
$inputFields = $xpath->query("//form[contains(@action,'login.jsf')]/input/@*");
It returns me all the input nodes with all the attributes but I only need name and value attributes otherwise I will have to run loop around all the attributes and discard all others except name and value. Basically I want to “select all the input nodes only with name and value attributes.”
I need to create an post array based on name and value attribute values.
I have tried following
$inputFields = $xpath->query("//form[contains(@action,'login.jsf')]/input/[@name | @value]");
But this doesn’t work.
You can use the
namefunction to get a name of an attribute: