XML Parse question

Hi all

Having a scratch you head moment here.

I have an xml feed to read which contains data such as


<?xml version="1.0" encoding="utf-8"?>
<root>
  <agentGroup code="5752">
    <mode>FULL</mode>
    <exportDate>2013-05-29T21:00:00</exportDate>
    <agentBranch code="199">
      <property propertyID="1227">
        <fullPostCode></fullPostCode>
        <countryCode>FR</countryCode>
        <name>xxx</name>
        <address>xxx</address>
        <regionCode>xxx</regionCode>
        <summary><=!=[=C=D=A=T=A=[xxxxxxx...]=]=></summary>
        <details><=!=[=C=D=A=T=A=[xxxxxxxxxxxxxxxxxxxxxxx.]=]=></details>
        <pricePrefix>xxxxx</pricePrefix>
        <price>xxxx</price>
       </property>

        repeat properties
 
    </agentBranch>
  </agentgroup>
</root>

using the following code I can access data that is a subset of <property>, but I cant seem to access the second part of the property tag “propertyID=1227”


foreach ($properties->agentGroup->agentBranch->property as $entry) { // gets each property

  $kfpropref = $entry->property->propertyID;    // THIS LINE DOESNT WORK
  $address = $entry->address;
  $summary = addslashes($entry->summary);
  $details = addslashes($entry->details);
  $price = $entry->price;
  $state = $entry->sellingState;
  $keywords = addslashes($entry->additionalKeywords);

}



How can I extract that info

TIA

OK, Ive found it.

Bizzarely this works

$kfpropref = $entry->attributes()->propertyID;

Not that I have anything against writing your own parser or anything but I recommend you look into the DOMCrawler that is a component within Symfony 2. The DOMCrawler coupled with the [url=http://symfony.com/doc/current/components/css_selector.html]CSSSelector component make for a very powerful DOM parser. If you need to do a lot of parsing than using a library is the way to go. Especially one as well written as DOMCrawler. Just thought I would throw that out there.

thanks oddz Ill give it a look

To access an attribute, array-style syntax can be used.

$entry['propertyID']

See also http://php.net/simplexml.examples-basic