0

I need to make a simple bash currency converter. I need to read information from xml file. I've written xml file and i don't know what to do next. Any ideas?

XML file:

<rates>
<currency>
    <name>Australian dollar</name>
    <rate>2.34</rate>
    <amount>1</amount>
</currency>
<currency>
    <name>GB Pounds</name>
    <rate>4.12</rate>
    <amount>1</amount>
</currency>
<currency>
    <name>Euro</name>
    <rate>3.45</rate>
    <amount>1</amount>
</currency>
<currency>
    <name>USA dollar</name>
    <rate>2.55</rate>
    <amount>1</amount>
</currency>
<currency>
    <name>Russian ruble</name>
    <rate>7.72</rate>
    <amount>100</amount>
user2939526
  • 21
  • 1
  • 3

2 Answers2

0

You can use xmllint to read values from the xml and then make the conversion

euro=$(xmllint --xpath '/rates/currency[name="Euro"]/rate/text()' rates.xml)
echo $euro
LMC
  • 10,453
  • 2
  • 27
  • 52
  • Ok that helps. But how do i implement it so let's say i want to exchange 7 GB pounds to dollars? – user2939526 Nov 27 '13 at 14:02
  • this could help http://stackoverflow.com/questions/14879133/currency-converter. And other idea... http://www.shell-fu.org/lister.php?id=821 – LMC Nov 27 '13 at 14:17
0

We know that you want to implement it in bash. However if possible, use perl or python for parsing xml. It has good liabraries for such tasks and it's easy to implement also.

Mandar Pande
  • 12,250
  • 16
  • 45
  • 72