加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用xmllint命令行的模式

发布时间:2020-12-16 01:47:32 所属栏目:安全 来源:网络整理
导读:]$xmllint --versionxmllint: using libxml version 20626 我的xml文件看起来像这样: projects architecture name="ARCH1" project label="StringA1" type="StringB1" state="StringC1"/ ...... /architecture architecture name="ARCH2" project label="St
]$xmllint --version
xmllint: using libxml version 20626

我的xml文件看起来像这样:

<projects>
 <architecture name="ARCH1">
  <project label="StringA1" type="StringB1" state="StringC1"/>
   ......
 </architecture>
 <architecture name="ARCH2">
  <project label="StringA2" type="StringB2" state="StringC2"/>
  ......
 </architecture>
</projects>

例如,我想在条件名称== ARCH2和state == StringC2的情况下获取值StringB2.是否可以使用xmllint命令行选项,如果是,如何?一些例子将是有益的.

我可以使用sed或awk提取这些,但这可能不是一个好的解决方案.

解决方法

使用:

xmllint --xpath '//architecture[@name="ARCH2"]/project/@type'

或者如果你只想要字符串而只需要字符串:

xmllint --xpath 'string(//architecture[@name="ARCH2"]/project/@type)'

在测试此语句时,我意识到,xmllint(20708)的ubuntu(12.04)版本在执行此命令时以段错误终止.我从https://git.gnome.org/browse/libxml2/refs/克隆了最新版本并编译.现在上面的命令有效.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读