xmlstarlet - 搜索属性

时间:2012-01-31 11:06:50

标签: xml shell

以xml为例:

<epp:phrases xmlns="http://www.w3.org/1999/xhtml" xmlns:epp="http://eprints.org/ep3/phrase" xmlns:epc="http://eprints.org/ep3/control">
  <epp:phrase id="Plugin/Screen/BatchEdit:title">Batch Editing Tool</epp:phrase>
  <epp:phrase id="Plugin/Screen/BatchEdit:action:edit">Apply Actions</epp:phrase>
  <epp:phrase id="Plugin/Screen/BatchEdit:edit_title">Modify Records</epp:phrase>
  <epp:phrase id="Plugin/Screen/BatchEdit:remove_title">Remove all Records</epp:phrase>
  <epp:phrase id="Plugin/Screen/BatchEdit:remove_help">Destroy all matching items. Once destroyed the items will be gone forever - this action <b>cannot be undone</b>!</epp:phrase>
  <epp:phrase id="Plugin/Screen/BatchEdit:confirm_remove">Are you absolutely sure you want to destroy all these items (this action cannot be undone)?</epp:phrase>
</epp:phrases>

如何使用xmlstarlet获取搜索@id属性的内部值?

所以如果我搜索“插件/屏幕/ BatchEdit:remove_title”我想要文本“删除所有记录”

你建议我使用的其他命令行脚本? 谢谢

1 个答案:

答案 0 :(得分:3)

可能是这样的:

//epp:phrase[@id="Plugin/Screen/BatchEdit:remove_title"]/text()

修改

$ xmlstarlet sel -t -v '//epp:phrase[@id="Plugin/Screen/BatchEdit:remove_title"]/text()' x.xml