5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

xmllint を使って、xmlをパースした

Last updated at Posted at 2021-10-09

個人用メモっす。

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.

5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?