I am trying to create a feed for Google Merchant using php and DOM document.
The feed contains thousands of items, yet fails to validate because there are a tiny handful of cases(4/5 out of 6000+) where the XML is malformed, for example:
 <g:product_type>Plantsg:product_type>
I am generating in a foreach loop
    //Loop through each plant
    foreach($plantList as $plantItem){
        //begin item element
        $item = $xml->createElement('item');
        //Loop through use key as element name and value as data
        foreach ($plantItem as $key => $value)
        {
            //Decode HTML characters, for example '&' becomes  &
            //to comply with http://www.w3.org/TR/xhtml1/#C_12
            $decode = htmlspecialchars_decode($value);
            $decode = trim($decode);
            if(empty($decode))
              continue;
            //Create the element
            $tag = $xml->createElement($key);
            $tag = $item->appendChild($tag);
            //Write the field
            $text = $xml->createTextNode($decode);
            $text = $tag->appendChild($text);
        }
        $item = $channel->appendChild($item);
    }
Here is the xml entire generation code.
Here are the 3 malformed tags:
g:adwords_grouping>18</g:adwords_grouping>
form>10 ltr pot</form>
title>Buy Helleborus x nigercors</title>
The malformed tags pop up in different places when I make adjusments to the code. Usually its either missing '
Thanks to all those who tried to solve it. The malformed tags were put there by Chrome when it encounters an encoding problem.
See 
 . In this case it opened the ,  tag encountered 'ö', then fell over and didn't close the  tag.
I am also incorrectly using htmlspecialchars_decode when I should be using just htmlspecialchars as pointed out by hakre, but thats a whole different problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With