DomDocument xml question:
希望 XML 看起来像这样
<itunes:category text="Main Category">
<itunes:category text="Sub category"/>
</itunes:category>
但相反,它看起来像这样
<itunes:category>text="Main Category"</itunes:category>
<itunes:category>text="Sub Category"</itunes:category>
这是 PHP:
$chan3 = $chan->appendChild($xml->createElement('itunes:category','text="Main Category"'));
$chan3 = $chan->appendChild($xml->createElement('itunes:category', 'text="Sub Category"'));
无法正确嵌套这些 xml 标记。不希望 itunes:category 关闭子类别上的标记。我是否使用 createElement 以外的其他东西?
这里的代码
$xml= new DOMDocument();
$xml->formatOutput = true;
$chan = $xml->createElement('itunes:category');
$chan = $xml->appendChild($chan);
$chan->setAttribute('text','Main Category');
$chan->nodeValue = '<itunes:category text="Sub category"/>';
echo $xml->saveXML();
结果是 ;
<itunes:category text="Main Category">
<itunes:category text="Sub category"/>
</itunes:category>
有好的一天。