-
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
1 parent
a8a143f
commit 0dae3f1
Showing
5 changed files
with
47 additions
and
52 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,2 @@ | ||
output | ||
test.sh |
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 |
---|---|---|
@@ -1,24 +1,37 @@ | ||
# xmllint demo | ||
# xmllint & xmlstarlet demo | ||
|
||
> A simple bash script to explore xmllint usage | ||
> A simple bash script to explore xmllint & xmlstarlet usage | ||
[xmllint Documentation](http://www.xmlsoft.org/xmllint.html)<br /> | ||
[xmlstarlet Documentation](http://xmlstar.sourceforge.net/docs.php)<br /> | ||
|
||
### Installation | ||
Ubuntu, run apt-get install libxml2-utils (if not installed already)<br /> | ||
Mac OS X (Yosemite), installed by default | ||
### Installation for xmllint | ||
Mac OS X (Yosemite) installed by default<br/> | ||
|
||
Ubuntu: sudo apt-get install libxml2-utils | ||
|
||
|
||
### Installation for xmlstarlet | ||
For Mac: brew install xmlstarlet | ||
For Ubuntu: sudo apt-get install xmlstarlet | ||
|
||
### xmllint usage demos in this project | ||
1. --xpath | ||
2. --repeat | ||
3. --timing | ||
|
||
### xmlstarlet usage demos in this project | ||
1. -ed -d | ||
2. -ed -u | ||
|
||
### Running the demo | ||
|
||
Project includes below sample xml files<br/> | ||
Project includes below sample xml file<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 | ||
### Make xmllint-demo.sh executable and run the script | ||
./xmllint.sh data/books.xml | ||
|
||
|
||
### Make xmlstarlet-demo.sh executable and run the script | ||
./xmlstarlet.sh data/books.xml |
This file was deleted.
Oops, something went wrong.
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
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,21 @@ | ||
#!/bin/bash | ||
|
||
function main() { | ||
# check if file is food.xml | ||
if [ $1 == 'data/books.xml' ]; then | ||
processBookstore $1 | ||
fi | ||
} | ||
|
||
function processBookstore() { | ||
xmlstarlet ed -d '/bookstore/book[@category="cooking"]' $1 > output/books-d.xml | ||
xmlstarlet ed -u '/bookstore/book[@category="cooking"]/@category' -v 'baking' $1 > output/books-u.xml | ||
xmlstarlet ed -u '/bookstore/book[@category="cooking"]/title' -v 'Everyday baking' $1 > output/books-uv.xml | ||
xmlstarlet ed -u '/bookstore/book[@category="cooking"]/title[@lang="en"]/@lang' -v 'es' $1 > output/books-uv1.xml | ||
xmlstarlet ed -u '/bookstore/book/@category' -v 'food' $1 > output/books-uv2.xml | ||
} | ||
|
||
# create output DIR if not presetn | ||
mkdir -p output | ||
echo 'File being read -' $1 | ||
main $1 |