I am trying to generate a Google Merchant RSS Feed, using PHP's SimpleXML and DOMDocument.
The actual generating code goes like that:
$dom = new DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$pRSS = $dom->createElement('rss');
$pRSS->setAttribute('version', '2.0');
$pRSS->setAttribute('xmlns:g', 'http://base.google.com/ns/1.0');
$dom->appendChild($pRSS);
$domnode = dom_import_simplexml($xml);
$domnode = $dom->importNode($domnode, true);
$domnode = $dom->appendChild($domnode);
$dom->save('googleproductfeed.xml');
($xml has all the data, but it's not relevant to my problem)
It all gets generated fine, but there is an XML error here:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2" xmlns:g="http://base.google.com/ns/1.0"/>
According to Google Merchant, Google Chrome and validome.org, there is an error in the second line.
More precisely, Validome says that it should not end with />
, but just >
.
The problem is I have no control over that. That part was generated by:
$pRSS = $dom->createElement('rss');
$pRSS->setAttribute('version', '2.0');
$pRSS->setAttribute('xmlns:g', 'http://base.google.com/ns/1.0');