2012-01-31 87 views
1

给出这个XML作为例子:xmlstarlet - 搜索属性

<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”我要你给我建议使用文本“删除所有记录”

其他命令行脚本? 谢谢

+0

请问,如果你尝试我的回答工作? – 2012-01-31 12:26:14

回答

2

大概是这样的:

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

编辑:

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

好,它的工作原理,但需要指定名称空间:xml sel -N epp =“http://eprints.org/ep3/phrase” – 2012-02-03 10:16:23