We already have a working XML that we make available on a link for Google Merchant Center to use (for a webshop in gardening products). In short it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://ift.tt/r5ut6F" xmlns:g="http://ift.tt/15FVsV8">
<title>Companyname product data feed</title>
<link rel="self" href="http://igarden.nl"/>
<updated>2014-07-08 08:23:18</updated>
<author>
<name>Our companyname</name>
</author><id>tag:companyname.nl,2014-07-08</id>
<entry>
<id>1001</id>
<title>Productname</title>
<link href="http://companyname.nl/"/>
<g:price>123,10</g:price>
<description>omschrijving van het product</description>
<g:condition>new</g:condition>
<g:brand>acd</g:brand>
<g:mpn>12321</g:mpn>
<g:ean>21353532235</g:ean>
<g:image_link>http://ift.tt/1kyLcAa;
<g:product_type>Huis & Tuin > category</g:product_type>
<g:availability>in stock</g:availability>
<g:shipping>
<g:country>NL</g:country>
<g:service>Standaard</g:service>
<g:price>6,50</g:price>
</g:shipping>
<g:manufacturer>acd2</g:manufacturer>
<g:weight>100g</g:weight>
<g:featured_product>0</g:featured_product>
<g:size>20x20x20</g:size>
</entry>
</feed>
We're remaking the webshop, so I wanted to try to make it with DOMDocument, but I find it difficult. This is what I have so far in code:
/* create a dom document with encoding utf8 */
$domtree = new DOMDocument('1.0', 'UTF-8');
/* create the root element of the xml tree */
$xmlRoot = $domtree->createElement("feed");
$xmlRoot = $domtree->appendChild($xmlRoot);
$addProduct = $domtree->createElement("entry");
$addProduct = $xmlRoot->appendChild($addProduct);
$addProduct->appendChild($domtree->createElement('id','100123'));
$addProduct->appendChild($domtree->createElement('title','Blokhut'));
$addProduct->appendChild($domtree->createElement('g:price','123,50'));
$addProduct->appendChild($domtree->createElement('description','omschrijving van de blokhut'));
$addProduct->appendChild($domtree->createElement('g:condition','new'));
/* get the xml printed */
header("Content-Type: text/plain");
$domtree->formatOutput = true;
echo $domtree->saveXML();
Which outputs:
<?xml version="1.0" encoding="UTF-8"?>
<feed>
<entry>
<id>100123</id>
<title>Blokhut</title>
<g:price>123,50</g:price>
<description>omschrijving van de blokhut</description>
<g:condition>new</g:condition>
</entry>
</feed>
So I got the basics working, but I have no clue how to make some elements working. How do I make these rows:
- Add this part to
<feed>
:<feed xmlns="http://ift.tt/r5ut6F" xmlns:g="http://ift.tt/15FVsV8">
<title>Compayname product data feed</title>
<link href="http://companyname.nl/"/>
- The
<g:shipping>
sub part
If I know how to make these, I think I can fill in the rest of the XML. I've tried so many things I found on here and by Googling, but I can't get them to work.
No comments:
Post a Comment