ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Re: XML::LibXML namespaces after node removal
by Petr Pajas other posts by this author
Sep 2 2005 2:08AM messages near this date
view in the new Beta List Site
Re: XML::LibXML namespaces after node removal | Regarding LibXML installation
& XSLT On Friday 02 of September 2005 09:36, Dominic Mitchell wrote:
>  I have a problem with namespaces after removal of a node from a
>  document.  I want to remove a node, then write it out to disk as
>  a standalone fragment.  But the namespace declarations are going
>  missing.
> 
>  For example:
> 
>     my $doc = $p->parse_string(
>       '<foo xmlns:bar="http://example.com/"><bar:bar /></foo>'
>     );
>     my $barbar = $doc->firstChild->firstChild;
>     $barbar->unbindNode();
>     print $barbar->toString();
> 
>  Outputs:
> 
>     <bar:bar/>
> 
>  Instead of:
> 
>     <bar:bar xmlns="http://example.com/"/>
> 
>  And I can't see why this is happening?  Can anyone help me with
>  this? I've attached the above as a test.

Hi Dominic,
The behaviour of $node-> toString is (IMHO) still correct. You have 
just unbound the node from the DOM tree but it still belongs to the 
tree and NS declarations will be added (if necessary) as soon as 
you try to attach it again. 

But this: create a new document and place your $barbar node into it:

$doc2 = XML::LibXML::Document-> new;
$doc2-> adoptNode($barbar); # not necessary, setDocElement does it 
anyway
$doc2-> setDocumentElement($barbar);
print $doc2-> toString;

Works for me.
-- Petr
Attachments:
unknown1
unknown2
unknown3
unknown4

Thread:
Dominic Mitchell
Robin Berjon
Dominic Mitchell
Robin Berjon
Dominic Mitchell
Petr Pajas

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved