XML::LibXML Oddity

This afternoon at work, I came across something most odd with XML::LibXML: When you call removeChild() on an element, it loses its namespace declarations. For example, if I have this XML:

  <bar:bar xmlns:bar="" />

Then, I call removeChild() on the <bar:bar> element, immediately followed by $node-&gt;toString(). And this is what I get back:


Which is not well formed XML because the namespace declaration is missing. Somewhere along the line, the declaration is being lost. I suspect that it should be copied in to the $node when it’s removed from its parent document, but that’s not happening. As to whether this is a bug in XML::LibXML or libxml2, I don’t know. I’ll file a report and we’ll see what happens.

Update: how odd. This minimal test case works as expected. I’ll have to examine the original situation more closely to work out what I’m not reproducing…

Update#2: I got the example wrong. Actually, the source xml looked like this:

&lt;foo xmlns:bar=""&gt;
  &lt;bar:bar /&gt;

This fails as expected.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s