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
bitnami@ip-10-212-187-224:~/sfb-link/scripts$ xmlstarlet sel -N x= http://opensearch.org/searchsuggest2 -t -v "/SearchSuggestion/Section/Item" bullwinkle.xml bitnami@ip-10-212-187-224:~/sfb-link/scripts$
that doesn't work (null response). not sure whether it's xpath or my lack of understanding of xmlstarlet.
----------------------------------------------------- Subscribe to the Nimble Books Mailing List http://eepurl.com/czS- for monthly updates
On Mon, Jan 9, 2012 at 17:34, b-jorsch@alum.northwestern.edu wrote:
On Mon, Jan 09, 2012 at 03:12:23PM -0500, Fred Zimmerman wrote:
count(/SearchSuggestion/Section/@Item)
That's looking for the "Item" in <Section Item="...">, of which none exist in the document. Lose the @ and it might work.
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
If you define namespace alias (in your case "x"), you also have to actually use it in the query:
xmlstarlet sel -N x=http://opensearch.org/searchsuggest2 -t -v 'count(/x:SearchSuggestion/x:Section/x:Item)' bullwinkle.xml
The command above works for me and returns "7".
And as far as I know, you have to use namespace aliases when working with XPath.
Petr Onderka [[User:Svick]]
On Tue, Jan 10, 2012 at 00:09, Fred Zimmerman wfz@nimblebooks.com wrote:
bitnami@ip-10-212-187-224:~/sfb-link/scripts$ xmlstarlet sel -N x=http://opensearch.org/searchsuggest2 -t -v "/SearchSuggestion/Section/Item" bullwinkle.xml bitnami@ip-10-212-187-224:~/sfb-link/scripts$
that doesn't work (null response). not sure whether it's xpath or my lack of understanding of xmlstarlet.
Subscribe to the Nimble Books Mailing List http://eepurl.com/czS-%C2%A0for monthly updates
On Mon, Jan 9, 2012 at 17:34, b-jorsch@alum.northwestern.edu wrote:
On Mon, Jan 09, 2012 at 03:12:23PM -0500, Fred Zimmerman wrote:
count(/SearchSuggestion/Section/@Item)
That's looking for the "Item" in <Section Item="...">, of which none exist in the document. Lose the @ and it might work.
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
thanks!
----------------------------------------------------- Subscribe to the Nimble Books Mailing List http://eepurl.com/czS- for monthly updates
On Tue, Jan 10, 2012 at 10:30, Petr Onderka gsvick@gmail.com wrote:
If you define namespace alias (in your case "x"), you also have to actually use it in the query:
xmlstarlet sel -N x=http://opensearch.org/searchsuggest2 -t -v 'count(/x:SearchSuggestion/x:Section/x:Item)' bullwinkle.xml
The command above works for me and returns "7".
And as far as I know, you have to use namespace aliases when working with XPath.
Petr Onderka [[User:Svick]]
On Tue, Jan 10, 2012 at 00:09, Fred Zimmerman wfz@nimblebooks.com wrote:
bitnami@ip-10-212-187-224:~/sfb-link/scripts$ xmlstarlet sel -N x=http://opensearch.org/searchsuggest2 -t -v "/SearchSuggestion/Section/Item" bullwinkle.xml bitnami@ip-10-212-187-224:~/sfb-link/scripts$
that doesn't work (null response). not sure whether it's xpath or my
lack of
understanding of xmlstarlet.
Subscribe to the Nimble Books Mailing List http://eepurl.com/czS- for monthly updates
On Mon, Jan 9, 2012 at 17:34, b-jorsch@alum.northwestern.edu wrote:
On Mon, Jan 09, 2012 at 03:12:23PM -0500, Fred Zimmerman wrote:
count(/SearchSuggestion/Section/@Item)
That's looking for the "Item" in <Section Item="...">, of which none exist in the document. Lose the @ and it might work.
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
now it's doing what I want it do with MediaWiki API (i.e producing csv of titles and URLs):
xmlstarlet sel -N x="http://opensearch.org/searchsuggest2" -t -m "//x:Item" -v "x:Text" -o ", " -v "x:Description" -o ", " -v "x:Url" -n bullwinkle.xml
Thanks again.
----------------------------------------------------- Subscribe to the Nimble Books Mailing List http://eepurl.com/czS- for monthly updates
On Tue, Jan 10, 2012 at 10:30, Petr Onderka gsvick@gmail.com wrote:
If you define namespace alias (in your case "x"), you also have to actually use it in the query:
xmlstarlet sel -N x=http://opensearch.org/searchsuggest2 -t -v 'count(/x:SearchSuggestion/x:Section/x:Item)' bullwinkle.xml
The command above works for me and returns "7".
And as far as I know, you have to use namespace aliases when working with XPath.
Petr Onderka [[User:Svick]]
On Tue, Jan 10, 2012 at 00:09, Fred Zimmerman wfz@nimblebooks.com wrote:
bitnami@ip-10-212-187-224:~/sfb-link/scripts$ xmlstarlet sel -N x=http://opensearch.org/searchsuggest2 -t -v "/SearchSuggestion/Section/Item" bullwinkle.xml bitnami@ip-10-212-187-224:~/sfb-link/scripts$
that doesn't work (null response). not sure whether it's xpath or my
lack of
understanding of xmlstarlet.
Subscribe to the Nimble Books Mailing List http://eepurl.com/czS- for monthly updates
On Mon, Jan 9, 2012 at 17:34, b-jorsch@alum.northwestern.edu wrote:
On Mon, Jan 09, 2012 at 03:12:23PM -0500, Fred Zimmerman wrote:
count(/SearchSuggestion/Section/@Item)
That's looking for the "Item" in <Section Item="...">, of which none exist in the document. Lose the @ and it might work.
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
mediawiki-api@lists.wikimedia.org