Skip to content

Instantly share code, notes, and snippets.

@LiosK
Created May 4, 2010 02:54
Show Gist options
  • Save LiosK/388887 to your computer and use it in GitHub Desktop.
Save LiosK/388887 to your computer and use it in GitHub Desktop.
a code snippet to extract pricedb from gzipped gnucash xml file
#!/usr/bin/perl
# extract pricedb from gzipped gnucash xml file
use utf8;
use strict;
use warnings;
use XML::LibXML;
die 'specify gnucash xml file as argument' unless $ARGV[0];
my $doc = XML::LibXML->load_xml(location => $ARGV[0]);
if (my $db = $doc->getElementsByTagName('gnc:pricedb')->shift()) {
# add explicit namespace declarations
for my $prefix ('price', 'cmdty', 'ts') {
$db->setNamespace($db->lookupNamespaceURI($prefix), $prefix, 0);
}
my $dbdoc = XML::LibXML::Document->new();
$dbdoc->setDocumentElement($db);
print $dbdoc->serialize();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment