XML into database

I’m trying to get the results of an xml into a database but all I get is errors. This is the code I’m using to get the xml file into the database:

<?php
$xml = simplexml_load_file('feed.xml');
foreach($xml->children() as $product) { 
mysql_query("INSERT INTO data (name,desc,tracking,brand) 

 VALUES ('$product->text->name','$product->text->desc','$product->uri->Track','$product->brand->brandName')");
} 
?>

and this is the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cafProductFeed SYSTEM "http://www.window.com/DTD/affiliate/datafeed.1.4.dtd">
<cafProductFeed>
<datafeed id="36" merchantId="36" merchantName="Company">
<prod id="12345678">
    <brand>
        <brandName>Universal Pictures</brandName>
    </brand>
    <cat>
        <CatId>550</CatId>
        <Cat>Blu-Ray</Cat>
        <mCat>Blu-ray</mCat>
    </cat>
    <price curr="USD">
        <buynow>44.99</buynow>
        <delivery>1.99</delivery>
        <store>0.00</store>
    </price>
    <text>
        <name>Product</name>
        <desc>description text</desc>
    </text>
    <uri>
        <Track>http://www.tracking.com</Track>
        <Image>http://images.domain.com/</Image>
        <mImage>http://www.images.domain.com</mImage>
        <mLink>http://www.domain.com/blu-ray/bourne-identity/the-bourne-supremacy/the-bourne-ultimatum/</mLink>
    </uri>
    <vertical/>
    <pId>1234567</pId>
    <largeImage>http://large.image.com</largeImage>
    <ean>1234567</ean>
</prod>
<prod id="12345678">
    <brand>
        <brandName>Universal Pictures</brandName>
    </brand>
    <cat>
        <CatId>550</CatId>
        <Cat>Blu-Ray</Cat>
        <mCat>Blu-ray</mCat>
    </cat>
    <price curr="USD">
        <buynow>44.99</buynow>
        <delivery>1.99</delivery>
        <store>0.00</store>
    </price>
    <text>
        <name>Product</name>
        <desc>description text</desc>
    </text>
    <uri>
        <Track>http://www.tracking.com</Track>
        <Image>http://images.domain.com/</Image>
        <mImage>http://www.images.domain.com</mImage>
        <mLink>http://www.domain.com/blu-ray/bourne-identity/the-bourne-supremacy/the-bourne-ultimatum/</mLink>
    </uri>
    <vertical/>
    <pId>1234567</pId>
    <largeImage>http://large.image.com</largeImage>
    <ean>1234567</ean>
</prod>
</datafeed>
</cafProductFeed>

but all I get is errors:

Warning: simplexml_load_file(): http://www.domains.co.uk/feed.xml:1: parser error : Space required after the Public Identifier in /home/domain/parse.php on line 2

Warning: simplexml_load_file(): in /home/domain/parse.php on line 2

Warning: simplexml_load_file(): ^ in /home/domain/parse.php on line 2

Warning: simplexml_load_file(): http://www.domains.co.uk/feed.xml:1: parser error : SystemLiteral " or ’ expected in /home/domain/parse.php on line 2

Warning: simplexml_load_file(): in /home/domain/parse.php on line 2

Warning: simplexml_load_file(): ^ in /home/domain/parse.php on line 2

Warning: simplexml_load_file(): http://www.domains.co.uk/feed.xml:1: parser error : SYSTEM or PUBLIC, the URI is missing in /home/domain/parse.php on line 2

Warning: simplexml_load_file(): in /home/domain/parse.php on line 2

Warning: simplexml_load_file(): ^ in /home/domain/parse.php on line 2

Fatal error: Call to a member function children() on a non-object in /home/domain/parse.php on line 3

I’ve never done anything like this before and would be so grateful for some help please

XML doesn’t agree with the found DTD.

btw. I couldn’t locate the DTD file, so that’s another problem.

I used file_put_contents(“feed.xml”,gzdecode(file_get_contents($url))); to save the file so I guess the DTD part is part of the output - is there anything I can do to remove that?

The xml file is on a test server at the moment so unfortunately can’t be accessed externally but it is definitely there and if I go to it in a browser can be read.

nope, the DTD file is said to be found at http://www.window.com/DTD/affiliate/datafeed.1.4.dtd.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.