LoginSignup
0
0

More than 3 years have passed since last update.

xmlstarletコマンドでRDFデータを取得する

Last updated at Posted at 2020-08-26

 xmlstarlet コマンドでRDF形式のファイルを取得するときの備忘録です。
 以下のようなRDFファイルにおいて、title と link を取得することを想定します。

rss.rdf
<rdf:RDF xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:sec="http://jvn.jp/rss/mod_sec/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xml:lang="ja">
  <item>
    <title>タイトル</title>
    <link>https://example.com/no123456.html</link>
    <description>説明書き</description>
  </item>
</rdf:RDF>

この場合、-N オプションで名前空間を指定する必要があります。また、xmlns="http://purl.org/rss/1.0/" のように、名前空間接頭辞が無い定義については、x などの重複しない名前空間接頭辞を指定する必要があります。

# xmlstarlet sel -N rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns# -N x=http://purl.org/rss/1.0/ -t -m "//rdf:RDF/x:item" -v "x:title" -o " / " -v "x:link"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0