diff --git a/README.md b/README.md new file mode 100644 index 0000000..7e1a746 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# xmllint demo + +> A simple bash script to explore xmllint usage + +[xmllint Documentation](http://www.xmlsoft.org/xmllint.html)
+ +### Installation +Ubuntu, run apt-get install libxml2-utils (if not installed already)
+Mac OS X (Yosemite), installed by default + +### xmllint usage demos in this project +1. --xpath + +### Running the demo + +Project includes below sample xml files
+[books.xml](data/books.xml)
+[food.xml](data/food.xml)
+ +### Make app.sh executable and run the script + ./app.sh data/food.xml + ./app.sh data/books.xml \ No newline at end of file diff --git a/app.sh b/app.sh new file mode 100755 index 0000000..c0c624f --- /dev/null +++ b/app.sh @@ -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.........' \ No newline at end of file diff --git a/data/books.xml b/data/books.xml new file mode 100644 index 0000000..f4b0efd --- /dev/null +++ b/data/books.xml @@ -0,0 +1,31 @@ + + + + Everyday Italian + Giada De Laurentiis + 2005 + 30.00 + + + Harry Potter + J K. Rowling + 2005 + 29.99 + + + XQuery Kick Start + James McGovern + Per Bothner + Kurt Cagle + James Linn + Vaidyanathan Nagarajan + 2003 + 49.99 + + + Learning XML + Erik T. Ray + 2003 + 39.95 + + \ No newline at end of file diff --git a/data/food.xml b/data/food.xml new file mode 100644 index 0000000..e8866d5 --- /dev/null +++ b/data/food.xml @@ -0,0 +1,33 @@ + + + + Belgian Waffles + $5.95 + Two of our famous Belgian Waffles with plenty of real maple syrup + 650 + + + Strawberry Belgian Waffles + $7.95 + Light Belgian waffles covered with strawberries and whipped cream + 900 + + + Berry-Berry Belgian Waffles + $8.95 + Light Belgian waffles covered with an assortment of fresh berries and whipped cream + 900 + + + French Toast + $4.50 + Thick slices made from our homemade sourdough bread + 600 + + + Homestyle Breakfast + $6.95 + Two eggs, bacon or sausage, toast, and our ever-popular hash browns + 950 + + \ No newline at end of file