I am having trouble figuring out how to give XMLStarlet the right Xpath to query nodes in a Wikipedia XML document. This is an xpath problem, really, not a starlet problem. I don't understand how to formulate the xpath portion of the xmlstarlet call. Help!
curl "
http://en.wikipedia.org/w/api.php?action=opensearch&search=Bullwinkle&am..." -o bullwinkle.xml
returns: ?xml version="1.0"?> <SearchSuggestion version="2.0" xmlns=" http://opensearch.org/searchsuggest2"> <Query xml:space="preserve">Bullwinkle</Query>
<Section> <Item> <Text xml:space="preserve">Bullwinkle</Text> <Description xml:space="preserve">Bullwinkle may refer to:</Description> <Url xml:space="preserve">http://en.wikipedia.org/wiki/Bullwinkle</Url> </Item> <Item> <Text xml:space="preserve">Bullwinkle J. Moose</Text> <Description xml:space="preserve">Bullwinkle J. </Description> <Url xml:space="preserve">http://en.wikipedia.org/wiki/Bullwinkle_J._Moose</Url> ...
I try:
xmlstarlet sel -N x=http://opensearch.org/searchsuggest2 -t -v "count(/SearchSuggestion/Section/@Item)" bullwinkle.xml
which I want to count the items, but it won't.
WHat I am working to do is to extract the text and url values and put them into a csv file. How to do this is explained at http://xmlstar.sourceforge.net/doc/UG/ch04s01.html (about 2/3 way down) but you have to know how to formulate the xpath for the source xml doc--which I don't!
Any help would be much appreciated.
----------------------------------------------------- Subscribe to the Nimble Books Mailing List http://eepurl.com/czS- for monthly updates