How to extract xml file generated by Grisbi
For those who know the software, I use Grisbi for my accounts. I want to extract the xml file generated by Grisbi of my accounts balances and this command line.
xml file looks like this:
<Accounts>
<Account>
...
<Balance_current> 99999999 <Balance_current>
...
</Account>
...
</Accounts>
I found as xmllint utility, but I did not think it meets my necessities. If you have an idea then do help me!
Re: How to extract xml file generated by Grisbi
The shell is not the best way to extract info from a XML file. Perl is much more responsive, and it is rather simple (XML:: Simple same). Here is a simple example that you can just copy paste it into a (pseudo) terminal:
Code:
cat > /tmp/l.xml <<WTF
<?xml version="1.0" ?>
<!DOCTYPE Foobar>
<Foobar Version="1.0">
<Accounts>
<Account>
<Balance_current>99999999</Balance_current>
</Account>
</Accounts>
</Foobar>
WTF
perl -MXML::Simple -e '$c = XMLin("/tmp/l.xml" ); print $c->{Accounts}->{Account}->{Balance_current}, "\n";'
If you know perl, you just install this module if needed with the command:
Code:
# cpan -i XML::Simple
OR
Code:
perldoc XML::Simple
Re: How to extract xml file generated by Grisbi
I thought of perl but then my xml file is like this:
<? xml version = "1.0"?>
<Grisbi>
and not this:
<? xml version = "1.0"?>
<! DOCTYPE Foobar>
<Foobar Version="1.0">
The other problem is that if I have multiple accounts I have this error: Not a HASH reference at -e line 1.
I think we should manage it in perl.
Re: How to extract xml file generated by Grisbi
Consequently, you do not want to look
Code:
cat > /tmp/l.xml <<RTFM
<?xml version="1.0" ?>
<Grisbi>
<Accounts>
<Account>
<Balance_current>3,50$</Balance_current>
</Account>
</Accounts>
</Grisbi>
RTFM
perl -MXML::Simple -e '$c = XMLin("/tmp/l.xml" ); print $c->{Accounts}->{Account}->[1]->{Balance_current} ."\n";'