我想设置xpath()找到的某个节点的文本
<?php
$args = new SimpleXmlElement(
<<<XML
<a>
<b>
<c>text</c>
<c>stuff</c>
</b>
<d>
<c>code</c>
</d>
</a>
XML
);
// I want to set text of some node found by xpath
// Let's take (//c) for example
// convoluted and I can't be sure I'm setting right node
$firstC = reset($args->xpath("//c[1]/parent::*"));
$firstC->c[0] = "test 1";
// like here: Found node is not actually third in its parent.
$firstC = reset($args->xpath("(//c)[3]/parent::*"));
$firstC->c[2] = "test 2";
// following won't work for obvious reasons, …Run Code Online (Sandbox Code Playgroud)