norricorp has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am using XML::LibXML to do work with XML files. I clone a node which has no xmlns attributes but the clone does have these. I guess this is because a parent has the attributes and so the clone has taken them for completness.
Anyway, I tried removing the attributes using various combinations of removeAttribute and removeAttributeNS but can not get this to work.
If I getAttributes and list then each shows up
attribute name is xmlns:rdf
attribute value is http://zzzzzzzzzzzzzzzzzzzzzzz
attribute name is xmlns:dc
attribute value is http://yyyyyyyyyyyyyyyyyy/
attribute name is xmlns:lcd
attribute value is http://xxxxxxxxxxxxxxxxxxxxx/
But trying to access an attribute by name is not working.
Any ideas to what I should be doing?
Regards,
John

Replies are listed 'Best First'.
Re: Remove attribute in XML
by tobyink (Canon) on Jan 10, 2012 at 13:07 UTC

    Firstly, xmlns:foo might look like an attribute, and act like an attribute in some circumstances, but it's not really an attribute. Namespace declarations are treated differently to normal attributes in the DOM and XML Infoset. There isn't a reliable way to delete a namespace declaration from an element if it's being used somewhere in the element's subtree.

    Secondly, from your example you appear to be trying to process RDF. Don't try to process RDF with generic XML tools - use a dedicated RDF library such as RDF::Trine. (See also here.)

Re: Remove attribute in XML
by choroba (Cardinal) on Jan 10, 2012 at 13:10 UTC
    xmlns is not an attribute, it's a namespace. How do you get the node, how do you clone it?
    Update: code removed.
Re: Remove attribute in XML
by Anonymous Monk on Jan 10, 2012 at 13:23 UTC