DOM: how to import nodes and give them different namespace prefix
Posted
by thomasrutter
on Stack Overflow
See other posts from Stack Overflow
or by thomasrutter
Published on 2010-04-07T05:46:12Z
Indexed on
2010/04/07
5:53 UTC
Read the original article
Hit count: 264
I'm familiar with the DOMDocument::importNode method for importing a tree of nodes from some other document element.
However, what I was wondering is if I can automatically change the namespace prefix on a tree of nodes as I import them, that is, specify a new prefix for all nodes of that namespace.
Say the nodes, in their existing document, all have names like "name", "identity", and so on. When importing them into my new document they will be alongside other namespaces, so I'd like them to appear as "nicnames:name", "nicnames:identity" and so on. I'd like to be able to change this prefix programmatically so that in another context I may be able to import them as, for instance, "myprefix:name", "myprefix:identity" depending on the document they're imported into.
Can anyone help me understand how to do this? Thanks
© Stack Overflow or respective owner