Created
May 4, 2010 02:54
-
-
Save LiosK/388887 to your computer and use it in GitHub Desktop.
a code snippet to extract pricedb from gzipped gnucash xml file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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