I want to take an existing element and put a child inside of it. But I want the content of the pre-existing element to go inside the new element as well.
So I have <span class="folnum">Content</span> and I want to end up with <span class="folnum"><a href="link">content</a></span> and I was hoping I could do this with php's simpleXML parser.
Here's what I've got so far:
$folnum = $xmldoc->xpath("//span[@class='folnum']");
foreach ($folnum as $indivfolnum)
{
$child = $indivfolnum->addChild("a", "wholemsImage");
$child->addAttribute("href", (string) $indivfolnum);
}
What I get from this is <span class="folnum">Content<a href="link">wholemsImage</a></span>.
Obviously the addChild() method is adding new content as well, which is not really what I want. I want it to replace the text-content.