Problems? Is your data what you think it is? | |
PerlMonks |
XML::LibXML::Element appendChild/addChild not inheriting namespace?by szr (Scribe) |
on Dec 31, 2015 at 18:39 UTC ( [id://1151607]=perlquestion: print w/replies, xml ) | Need Help?? |
szr has asked for the wisdom of the Perl Monks concerning the following question:
I feel there is something I'm missing in regards to namespace inheritance in XML::LibXML.
Please consider the following:
Element foo:child is valid without a xmlns:foo="http://foo" attribute since that appears further up the tree, in the root node. What I don't quite understand is the behavior of addChild or appendChild of XML::LibXML::Node which doesn't seem to realize that prefix is associated with a namespace further up the tree (in the root node) and doesn't properly split foo:child. Which yields: child->prefix=, child->localname=foo:child When I would have expected: child->prefix=foo, child->localname=child I know createElementNS can be used, but that requires one to know what NS to pass rather than being able to rely on inheritance. What is even stranger is inheritance actually appears to work with attributes. If I add the following to the code above: I get this: an->prefix=foo, an->name=abc Also note the lack of using setAttributeNS method, as this is about inheritance, rather than manually specifying the namespace uri each time an attribute is added. So why doesn't this seem to work for elements? Maybe I'm really missing something, probably fairly obvious, as it seems this should be trivial. Thanks.
Back to
Seekers of Perl Wisdom
|
|