• Hi there,

    I try to get some xml feeds in a table called wp_xml_feeds. i get the follow error while my code seems right to me.

    Parse error: syntax error, unexpected ‘}’ in /sites/mywebsite.com/www/wp-content/plugins/xml-to-database/index.php on line 28

    <?php
    
    //I am using the DOM(Document Object Model) library to read the entire XML document into memory first.
    $doc = new DOMDocument();
    $doc->load('http://mywebsitexmlfeeds.com/?aid=50289&type=xml&encoding=utf-8&fid=631&categoryType=2&additionalType=2');
    
    //now I get all elements inside this document with the following name "products", this is the 'root'
    $products = $doc->getElementsByTagName("products")
    ;
    //now I go through each item withing $products
    foreach($products as $prod)
    {
    //I then find the 'product' element inside that loop
    $product = $prod->getElementsByTagName("product");
    foreach($product as $itemgotten)
    {
    
    //now I search within '$product' for the element "name"
    
    $idit = $itemgotten->getElementsByTagName("productID");
    $nameit = $itemgotten->getElementsByTagName("name");
    
    //once I find it I create a variable named "$name" and assign the value of the Element to it
    $id = $idit->item(0)->nodeValue;
    $name = $nameit->item(0)->nodeValue;
    
    //and write it to the db
    $wpdb->insert( 'wp_xml_feeds', array( 'id' => $id, 'name' => $name ), array( '%d' , '%s' ) )
    }
    }
    ?>

    Anyone got a clue?

The topic ‘Parse error while putting xml into database’ is closed to new replies.