in reply to XML::LibXML::Element appendChild/addChild not inheriting namespace?

If you want to add a new child with a namespace, use addNewChild:
my $c = $p->addNewChild('http://foo', 'child');

If you need to use the prefix and inheritance, combine it with lookupNamespaceURI:

my $c = $p->addNewChild($p->lookupNamespaceURI('foo'), 'child');
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: XML::LibXML::Element appendChild/addChild not inheriting namespace?
by szr (Scribe) on Jan 01, 2016 at 18:56 UTC
    Thank you for the reply. Yes, your method appears to work.

    One thing is still bugging me though, in regards to $child->localname yielding foo:child, which doesn't seem to be XML 1.0 compliant, as a colon usually isn't allowed in the localname or prefix parts, as it's reserved as the separator, yet localname contains it in my original test case above.

    Would this constitute a bug, or is this desired behavior somehow?
      I think the problem is already in createElement which accepts 'foo:child' without checking the prefix. I'm not sure whether it's a problem on the Perl or underlying C side, though.
      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,