Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sumeetsarkar committed Nov 16, 2017
0 parents commit 9f27d3f
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# xmllint demo

> A simple bash script to explore xmllint usage
[xmllint Documentation](http://www.xmlsoft.org/xmllint.html)<br />

### Installation
Ubuntu, run apt-get install libxml2-utils (if not installed already)<br />
Mac OS X (Yosemite), installed by default

### xmllint usage demos in this project
1. --xpath

### Running the demo

Project includes below sample xml files<br/>
[books.xml](data/books.xml)<br/>
[food.xml](data/food.xml)<br/>

### Make app.sh executable and run the script
./app.sh data/food.xml
./app.sh data/books.xml
28 changes: 28 additions & 0 deletions app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

function main() {
# check if file is food.xml
if [ $1 == 'data/food.xml' ]; then
processBreakfastMenu $1
# check if file is books.xml
elif [ $1 == 'data/books.xml' ]; then
processBookstore $1
fi
}

function processBreakfastMenu() {
echo $'usage of --path /breakfast_menu/food[1]\n'
xmllint --xpath '/breakfast_menu/food[1]' $1
}

function processBookstore() {
echo $'usage of --path /bookstore/book[@category="cooking"]/author/text()\n'
xmllint --xpath '/bookstore/book[@category="cooking"]/author/text()' $1
}

echo 'File being read -' $1
echo $'Output...\n'

main $1

echo $'\n\n.........'
31 changes: 31 additions & 0 deletions data/books.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
33 changes: 33 additions & 0 deletions data/food.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>

0 comments on commit 9f27d3f

Please sign in to comment.