Quantcast
Channel: Bashタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 2882

xmllint を触った

$
0
0
個人用メモっす。 xmlintとは shell scriptでxmlをパースしてくれる君。 使い方 自分が必要になった分だけメモる。 # linuxの場合 sudo apt update sudo apt install libxml2-utils # xmlを整形して表示 echo file.xml | xmllint --format - # 特定のpathのnodeを取得 xmllint --xpath "/testsuite/testcase/failure" tmp/test-results/rspec.xml # 以下出力 # <failure message="RSpec::Core::MultipleExceptionError" type="RSpec::Core::MultipleExceptionError"> # </failure><failure message="RSpec::Core::MultipleExceptionError" type="RSpec::Core::MultipleExceptionError"> # </failure> # そのnodeの特定の属性の値を取得する xmllint --xpath "/testsuite/testcase/failure/@message" tmp/test-results/rspec.xml # 以下出力 # message="RSpec::Core::MultipleExceptionError" # このnodeの親nodeを取得する xmllint --xpath "/testsuite/testcase/failure/parent::node()" tmp/test-results/rspec.xml # 以下出力 # <testcase classname="spec.features.post_articles_spec" name="Post Article Company post" file="./spec/features/post_articles_spec.rb" time="7.636209"><failure message="RSpec::Core::MultipleExceptionError" type="RSpec::Core::MultipleExceptionError"> # </failure></testcase><testcase classname="spec.features.post_articles_spec" name="Post Article User post" file="./spec/features/post_articles_spec.rb" time="1.935865"><failure message="RSpec::Core::MultipleExceptionError" type="RSpec::Core::MultipleExceptionError"> # </failure></testcase> Ref. 親nodeの取り方: https://chrome.hatenablog.jp/entry/2017/04/02/195139

Viewing all articles
Browse latest Browse all 2882

Trending Articles