-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9f27d3f
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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.........' |
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
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> |
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
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> |