I have this XML:
<p>
This is a test <xref>1</xref> in the XML <xref>2</xref> bla bla bla....
</p>
What I would like to do is to add the letter "N" just before the <xref>
For that, I tried to use DOMNode::insertBefore
but without success.
Ex:
$refs = $paragraph->getElementsByTagName("xref");
foreach ($refs as $key=>$ref) {
if ($key == 0) {
$N = $dom_input->createTextNode("N");
$citation->insertBefore($N);
}
}
But the N text node is not inserted.
Thank you in advance for your help.
I was able to fix the problem. I did a mistake, the code should look like:
if ($key == 0) {
$squareBracket = $dom_input->createTextNode("[");
$paragraph->insertBefore($squareBracket, $citation);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.