0

I am trying to read through an REA-XML file and using simplexml to convert the xml into an array

$xml = simplexml_load_string($data) or die("Error: Cannot create object");

There is a section in the XML that looks like this:

<images>
    <img id="a" modTime="2009-01-01-12:30:00" url="http://image.jpg" format="jpg"/>
    <img id="m" modTime="2009-01-01-12:30:00" url="https://image.jpg" format="jpg"/>
</images>

When converted to an array , an additional array element "@attributes" is created with the modTime etc in it.

However, in the same XML , same level:

<landDetails>
        <area unit="square">80</area>
        <frontage unit="meter">20</frontage>
        <depth unit="meter" side="rear">40</depth>
        <crossOver value="left"/>
</landDetails>

The "unit" attribute is missing completely, The value for "value" in the crossOver, is in an "@attributes" array, but the three other items for "unit" are missing completely from the var_dump

Why do the unit values not show up in the @attribute array, or anywhere else in the landDetails section?

full example XML:

http://rea-new-help.realestate.com.au.s159598.gridserver.com/wp-content/uploads/2013/05/rental_sample.xml

1 Answer 1

2

Quck pointer: php SimpleXML attributes are missing

Basically, SimpleXML and print_r/var_dump don't play nicely: if you iterate through the object tree e.g. $xml->area you'll see the object faithfully rendered:

SimpleXMLElement Object ( [@attributes] => Array ( [unit] => square ) [0] => 80 )

This is particularly true for Elements where there are both Attributes and Content.

Sign up to request clarification or add additional context in comments.

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.