SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing a child node in an XML feed

    I am looking to extract data from an XML feed containing information on books.

    The feed is set up like this:

    <product>
    <title></title>
    <price></price>
    <fields>
    <author></author>
    </fields>
    </product>
    Now, having set the parent node as 'product', I can access the title and price data without any problem.

    Here's the code I've got at the moment, but how do I amend it to access the 'author' information from the 'fields' node?

    PHP Code:

    case 'product';

    //initialise xml parser
    $dom = new DOMDocument();
    $domNode $xmlReader->expand();
    $element $dom->appendChild($domNode);
    $domString utf8_encode($dom->saveXML($element));
    $product = new SimpleXMLElement($domString);

    //import data
    $name $product->name;
    $product_url $product->url;
    $price $product->price;
    $author $product->author;
    $rank $product->rank;

    //insert query into database


            
    $query mysql_query("REPLACE INTO db_namet
            (rank, title, author, price, url)
            
            VALUES ('
    $rank', '$name', '$author', '$price', '$product_url')");
            
            echo 
    $product_name "has been inserted </br>"
    Thanks very much in advance for your help

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,169
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Try
    PHP Code:
    $author $product->fields->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
  •