1

I have written a xml/php document that is pulling from a Magento Commerce database, to create the XML document with all of the items in it, so that Google's Shopping can import the items. Google's system is getting hung up on a item, I believe that this is due to the special characters. I want to strip those characters out of the output. Notice in the output that there is a couple of registered trademarks, and some quotes, and commas. I doubt the quotes or commas are the problem, I think it may be the trademarks.

Here is the output

<title>The FoamZall - Spray Foam Insulation Trimming Foam Saw - w/ Open Cell Blade</title>
<description>The FOAMZALL includes the toughest Milwaukee® brand heavy-duty orbital Sawzall® around, which has a custom coupling to secure a 36" long serrated blade intended for trimming 1/2 lb and 2 LB foam.  The 13 Amp, 120 Vac saw has a 1 1/4" stroke and can provide up to 3,000 strokes per minute.  Carry case is included.   </description>
<g:google_product_category>Business &amp; Industrial &gt; Construction</g:google_product_category>
<g:product_type>Spray Foam Parts &amp; Supplies &gt; Fusion AP Parts</g:product_type>
<link>http://sprayfoamsys.com/store/the-foamzall-spray-foam-insulation-trimming-saw-open-cell-blade.html</link>
<g:image_link>http://sprayfoamsys.com/store/media/catalog/product/f/o/foamzall.jpg</g:image_link>
<g:condition>new</g:condition>
<g:availability>in stock</g:availability>
<g:price>425.0000</g:price>
<g:brand></g:brand>
<g:mpn></g:mpn>
</item>
<item>

My Script is:

<?php echo '<?xml version="1.0" ?>'; ?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://www.base.google.com/cns/1.0">
<channel>
<title>Spray Foam Systems</title>
<link>http://www.sprayfoamsys.com/store/</link>
<description>Spray Foam Rigs, Spray Foam Equipment, Sprayfoam Parts and Supplies.</description>
<?php
$con = mysql_connect(REMOVED) or die(mysql_error());
    if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
    mysql_select_db("sprayfoa_store", $con);

    $query = mysql_query("SELECT * FROM `catalog_product_flat_1` WHERE `visibility` = 4 ORDER BY entity_id asc")
    or die(mysql_error());
?>
<?php
    while($row = mysql_fetch_array($query))
        {
?>
<item>
<g:id><?php echo $row['entity_id']; ?></g:id>
<title><?php echo $row['name']; ?></title>
<description><?php echo (str_replace(array("\r\n", "\n"), ' ', $row['short_description'])); ?></description>
<g:google_product_category>Business &amp; Industrial &gt; Construction</g:google_product_category>
<g:product_type>Spray Foam Parts &amp; Supplies &gt; Fusion AP Parts</g:product_type>
<link>http://sprayfoamsys.com/store/<?php echo $row['url_path']; ?></link>
<g:image_link>http://sprayfoamsys.com/store/media/catalog/product<?php echo $row['small_image']; ?></g:image_link>
<g:condition>new</g:condition>
<g:availability>in stock</g:availability>
<g:price><?php echo $row['price']; ?></g:price>
<g:brand><?php $entity_id = $row['entity_id']; $query2 = mysql_query("SELECT * FROM `catalog_product_entity_varchar` WHERE entity_id = '$entity_id' AND attribute_id = '127'") or die(mysql_error()); while($row2 = mysql_fetch_array($query2)) { echo $row2['value']; } ?></g:brand>
<g:mpn><?php echo $row['sku']; ?></g:mpn>
</item>
<?php
}
mysql_close($con);
?>
</channel>
</rss>
11
  • Hm, haven't encountered it before. Do you specify a character set in your XML? What character set are you sending? And if it isn't utf-8, could you try that one?
    – Wrikken
    Feb 1, 2012 at 16:34
  • The error I get is an XML formatting error - Line 205 Column 559, line 205 is the <description> tag
    – user1106352
    Feb 1, 2012 at 16:38
  • Which encoding is the XML? Which encoding are the variables you get from the database? What is the XML output where it fails? Which encoding is valid for the google service? Why don't you use XML writer?
    – hakre
    Feb 1, 2012 at 17:12
  • will it work when you change the prolog to <?xml version="1.0" encoding="utf-8"?>?
    – Gordon
    Feb 1, 2012 at 17:14
  • @hakre - the XML is now utf-8, I am unsure of the encoding from the database, the xml output line that fails is now line 121 col 330, here is the line <description>The FOAMZALL includes the toughest Milwaukee� brand heavy-duty orbital Sawzall� around, which has a custom coupling to secure a 36" long serrated blade intended for trimming 1/2 lb and 2 LB foam. The 13 Amp, 120 Vac saw has a 1 1/4" stroke and can provide up to 3,000 strokes per minute. Carry case is included. </description>. I am unsure of the accepted encoding for google shopping.
    – user1106352
    Feb 1, 2012 at 18:42

1 Answer 1

1

I'm pretty sure any characters outside the 0-255 range should be encoded as &#___;.

3
  • that's wrong for XML, only some very few need entities and some characters just don't exist (like \x00). Most characters work if the document is properly encoded, e.g. UTF-8 is default for XML.
    – hakre
    Feb 1, 2012 at 16:52
  • That may be, but there may be restrictions on the API. Perhaps it only accepts documents in iso-8859-1, for instance. Feb 1, 2012 at 17:07
  • then there would be no characters outside of 0-255 anyway, however same for that encoding: some of those your answers says are valid aren't and the rest wouldn't need entities.
    – hakre
    Feb 1, 2012 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.