alan_olsen has asked for the wisdom of the Perl Monks concerning the following question:
I have a chunk of xml. I am using XML::LibXML to parse and mangle the data. If I unlink a node and then output the data to a file, the node is replaced by a blank line. Is there any way to change the behavior to not add the extranious whitespace?
Example:
Before xml removal: <item1/> <item2/> <item3/> After removing item2: <item1/> <item3/> Here is the sample code snippet (And yes, I pull the list using XML::S +imple.) my $manifesto = XMLin($google_manifest); foreach my $project (sort keys %{$manifesto->{'project'}}){ if ($project){ $project = 'a/aosp/' . $project; print "Project = $project \n"; my $query1 = '//project[@name = "' . $project . '"]'; my ($node) = $doc->findnodes($query1); if ($node){ $node->unbindNode(); } } } print $doc->toFile($new_manifest);
Ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing whitespace from deleted items in XML::LibXML
by ikegami (Patriarch) on Dec 08, 2011 at 22:56 UTC | |
|
Re: Removing whitespace from deleted items in XML::LibXML
by tobyink (Canon) on Dec 08, 2011 at 23:25 UTC | |
|
Re: Removing whitespace from deleted items in XML::LibXML
by choroba (Cardinal) on Dec 08, 2011 at 22:57 UTC |