Remove xmlns:* attribute based on URI scheme

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Remove xmlns:* attribute based on URI scheme

Post by Ambush Commander »

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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

getElementsByTagNameNS('http://namespaec/URI','*') should select all the nodes you're after... but I have no idea how to change / remove the NS :-(
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Actually, that won't even work either because I'm looking for the namespace declarations, not the actual elements that use the namespace. :-(
Post Reply