我有一些XML我需要添加一个孩子。SimpleXML添加孩子和属性
使用SimpleXML,我没有任何问题添加一个简单的节点。
的开始XML看起来有点像这样:
<root>
<item>
<title>This is the title</title>
<sort>2</sort>
</item>
<item>
<title>This is another title</title>
<sort>3</sort>
</item>
</root>
我需要补充的是这样的一个节点:
<label id=1>
<title type=normal>This is a label</title>
<sort>1</sort>
</label>
其结果将是:
<root>
<item>
<title>This is the title</title>
<sort>2</sort>
</item>
<item>
<title>This is another title</title>
<sort>3</sort>
</item>
<label id=1>
<title type=normal>This is a label</title>
<sort>1</sort>
</label>
</root>
我可以添加一个简单的孩子使用:
$xml->root->addChild('label', 'This is a label');
虽然我无法获取属性和子添加到这个新添加的节点。
我不担心在XSLT中进行排序时追加与预先计划相关。
你想要做什么说明书中加以说明。 http://docs.php.net/manual/en/simplexml.examples-basic.php(示例#10) – 2011-04-19 16:33:24