SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    XML Parse question

    Hi all

    Having a scratch you head moment here.

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

    Code:
    <?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"

    PHP Code:
    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
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK, Ive found it.

    Bizzarely this works

    $kfpropref = $entry->attributes()->propertyID;
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,048
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    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 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.
    The only code I hate more than my own is everyone else's.

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks oddz Ill give it a look
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  5. #5
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    54 Post(s)
    Tagged
    0 Thread(s)
    To access an attribute, array-style syntax can be used.

    Code php:
    $entry['propertyID']


    See also http://php.net/simplexml.examples-basic
    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •