XMLStarlet and RSS

可紊 提交于 2019-12-07 02:19:27

This XmlStarlet command:

xml sel -N purl="http://purl.org/rss/1.0/" -t -m "//rdf:RDF/purl:item" -v purl:title -n -v purl:description -n -v purl:link -n ./sss.rdf

Yields the desired output:

Unlocked Optimus Lg Phone (Baltimore) $150
OR WE CAN HAVE A SWAP FOR AN IPOD TOUCH 5g
●Optimus Lg Phone For Sale At 150.00 The Original Price Was $180.00
●It Does Not Include The Charger, But You Can Find It At Walmart For $4.00
●The Phone Was Only Used For 2-3 Months
&# [...]
http://baltimore.craigslist.org/ele/4039527375.html

Explanation:

The key is to notice that the input document has a default namespace, which causes item, title, description, and link to be in the http://purl.org/rss/1.0/ namespace. Defining -N purl="http://purl.org/rss/1.0/" allows us to use the purl prefix when specifying these elements in the XPaths. Without the purl namespace prefixes, the XPaths weren't matching.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!