0

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 question 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

2
  • Is the tag containing the <field> tags is <fields>? I don't know much about the XML reader. Maybe there is a way to split all of theses field into an array. Commented Apr 12, 2011 at 13:51
  • yes the orig tag is '<fields> <field name="latitude" value="51.4070767"/> <field name="longitude" value="-0.6366062"/> </fields>' Commented Apr 12, 2011 at 13:52

2 Answers 2

1

You need to make field an array, so that you can do:

$product->fields->field[0]["value"];
$product->fields->field[1]["value"];
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.