Reputation: 7472
how can I get the value
of this input using xpath?
<input type='text' name='name' value='john' />
Thanks
Upvotes: 0
Views: 205
Reputation: 11360
With SimpleXML,
$input_element = $your_xml_doc->xpath("//input[@name='name']");
$value = (String) $input_element[0]->attributes()->value;
Upvotes: 1
Reputation: 4193
You need to use the attribute selector, eg: //input/@value
There's more about selecting nodes here: w3schools.com and a nice tool for testing your XPath here.
Upvotes: 2
Reputation: 402
i think
//input/@value
would be enough if you had only this piece of code... but maybe you have more html around and you need to target :
//input[@name='name']/@value
Upvotes: 2