XMLReader() in PHP - parsing attributes in multiple elements with the same name
Im using XMLReader to parse XML but i've come across a situation where two elements have the same name and not sure how to deal with it
the elements in qu开发者_如何学Pythonestion are
<field name="latitude" value="51.4070767"/>
<field name="longitude" value="-0.6366062"/>
I want to pull in the two value fields into seperate strings.
I can pull in the first one using this method
$bp = $product->fields->field["value"]; ###gives 51.4070767
but how do i access the second? (-0.6366062)
Cheers
You need to make field
an array, so that you can do:
$product->fields->field[0]["value"];
$product->fields->field[1]["value"];
It's just one idea... You can find the node by attribute (getAttribute) and after you can select the node using moveToElement.
But the best option is use the simpleXML, where you can use XPath to find what you want.
精彩评论