PHP DOM文档生成格式错误的XML feed

use*_*072 6 php xml dom

我正在尝试使用php和DOM文档为Google Merchant创建Feed.

该Feed包含数千个项目,但无法验证,因为有少数情况(6000+中的4/5)XML格式不正确,例如:

 <g:product_type>Plantsg:product_type>
Run Code Online (Sandbox Code Playgroud)

我在foreach循环中生成

    //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  &amp
            //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);
    }
Run Code Online (Sandbox Code Playgroud)

这是xml整个代码.

以下是3个格式不正确的标签:

g:adwords_grouping>18</g:adwords_grouping>

form>10 ltr pot</form>

title>Buy Helleborus x nigercors</title>
Run Code Online (Sandbox Code Playgroud)

当我对代码进行调整时,格式错误的标签会弹出不同的位置.通常它要么缺少'

Ram*_*Ram 0

我和@aefxx 在一起,如果您可以在看到格式错误的开始标记的行之前和之后提供几行(看起来您显示的所有示例在开始标记中只缺少一个字符),那将会很有帮助。