Reputation: 559
I need to pick one tag from xml file and insert another tag before this tag. I'm doing this with method insertBefore
in DOM, but the problem is, that if I want pick the tag before I want to add the another tag by method getElementById
, it doesn't work.
It writes "using non-object". This is how the tag looks:
<item id="Flow_0" href="Flow_0.html" media-type="application/xhtml+xml"/>
Somewhere I read that it must look like this, but I can't edit all files:
<item xml:id="Flow_0" href="Flow_0.html" media-type="application/xhtml+xml"/>
Have you got any idea how to do that?
Upvotes: 2
Views: 1276
Reputation: 51950
A common workaround is to use XPath to get the element.
$item = $xpath->query('//item[@id="Flow_0"]')->item(0);
Upvotes: 2