这是一个后续的问题 这篇文章.
我想最终得到一个数组,包含
xml的所有元素.
array[0] = "]]>" array[1] = "]]>"
...
file.xml:
http://www.foobar.com/foo/bar
http://bar.com/foo
http://myurl.com/foo
http://desiredURL.com/files/ddd
http://asdasd.com/onefile/g.html
http://second.com/link
]]>...
Édouard Lope.. 10
一个Bash
解决办法是
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)" done echo ${description[@]}
考虑一下bash
可能不是正确的工具.XSLT/XPath可以让您直接访问description
元素的内容,如前面的答案中所述.例如:
xmllint --xpath '//item/description/text()' /tmp/so.xml
返回每个
内容