我從我的gmail帳戶中獲取一些我想分析的xml數據。 THS XML數據的樣子:xmllint和xpath從https://mail.google.com/mail/feed/atom解析xml數據
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://purl.org/atom/ns#" version="0.3">
<title>Gmail - Inbox for @gmail.com</title>
<tagline>New messages in your Gmail Inbox</tagline>
<fullcount>54</fullcount>
<link rel="alternate" href="http://mail.google.com/mail" type="text/html"/>
<modified>2014-11-25T04:40:04Z</modified>
<entry>
<title>test</title>
<summary/>
...
</feed>
和我跳得到所有條目的所有標題的東西,如:
xmllint --xpath '//feed/entry/title' myfile.xml
現在,我發現,如果有這樣的工作不是這個xmlns信息。 但隨着XMLNS信息,我得到的消息
的XPath設置爲空
我想一個簡單的oneliner來解析該文件,而無需修改文件(去除的xmlns部分)。
- >編輯:由於@Mathias,正確onliner看起來像: 回聲 「setns X = http://purl.org/atom/ns# \ nxpath/X:進料/ X:進入/ X:標題/文本()」
可能重複的[xmllint無法正確查詢與xpath](http://stackoverflow.com/questions/8264134/xmllint-failing-to-properly-query-with-xpath) – 2014-11-25 21:12:09