unplugged_web Posted September 8, 2015 Share Posted September 8, 2015 I'm trying to get the contents of a few xml files (all on the server) into a couple of different tables of a database but don't know how to do this. Does anybody have any ideas? All of the files are the same format wise and I need to put the details into two different tables. Thanks in advance Link to comment Share on other sites More sharing options...
unplugged_web Posted September 8, 2015 Author Share Posted September 8, 2015 This is what I've got so far 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(): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 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(): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 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(): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted September 8, 2015 Share Posted September 8, 2015 The error messages are pointing to an HTML doctype in the XML file. XML files shouldn't have an HTML doctype. Link to comment Share on other sites More sharing options...
unplugged_web Posted September 9, 2015 Author Share Posted September 9, 2015 The file was automatically saved from a feed so I wasn't able to change the output. I decided to use a cvs copy of the feed instead as that wasn't changed at all Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now