Remove xmlns:* attribute based on URI scheme
Posted: Sat Mar 17, 2007 1:52 pm
I have a DOMDocument. I know the URI of the namespace I want to remove, but I don't know the prefix. How do I remove all references to that namespace from my DOMDocument, without transforming it to text and regexping / xmlns:.+?\s*=\s*"$scheme"/ and replacing that with a blank?
A little background: I am using my own namespace to help cordon off proprietary extensions I'm making to XHTML (normally, I'd try to fit things into already valid HTML elements, but there's only so much one can do). A post-processor converts these to valid HTML, at which point they have no meaning anymore and should be removed. But I can't figure out how to!
Xmlns attributes seem to get special treatment from PHP's DOM specification. While getAttribute('xmlns:php') works properly, the xmlns attributes do not show up in the attributes property of an element. This is reasonable, as DOM is early binding and each node should be directly associated with the namespace URI. However, DOM is definitely retaining information on the original prefixes, otherwise it would have dropped the namespace declaration when it realized nothing was referencing it.
A little background: I am using my own namespace to help cordon off proprietary extensions I'm making to XHTML (normally, I'd try to fit things into already valid HTML elements, but there's only so much one can do). A post-processor converts these to valid HTML, at which point they have no meaning anymore and should be removed. But I can't figure out how to!
Xmlns attributes seem to get special treatment from PHP's DOM specification. While getAttribute('xmlns:php') works properly, the xmlns attributes do not show up in the attributes property of an element. This is reasonable, as DOM is early binding and each node should be directly associated with the namespace URI. However, DOM is definitely retaining information on the original prefixes, otherwise it would have dropped the namespace declaration when it realized nothing was referencing it.