Bash script: Get XML elements into array using xmllint
A Bash
solution could be
let itemsCount=$(xmllint --xpath 'count(//item/description)' /tmp/so.xml)declare -a description=( )for (( i=1; i <= $itemsCount; i++ )); do description[$i]="$(xmllint --xpath '//item['$i']/description' /tmp/so.xml)"doneecho ${description[@]}
Disclaimer
Consider that bash
may not be the right tool. XSLT/XPath could give you direct access to the content of the description
element as describe in previous answer. For instance:
xmllint --xpath '//item/description/text()' /tmp/so.xml
Return every <description>
content