xmllint如何读取具有android SharedReferences值的xml文件

xmllint如何读取具有android SharedReferences值的xml文件,xml,shell,xpath,xmllint,Xml,Shell,Xpath,Xmllint,我需要从android中的SharedReference文件中获取一个值。文件的xml如下所示: <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <map> <boolean name="apples" value="true" /> <boolean name="grapes" value="true" /> <boolean name="orange

我需要从android中的SharedReference文件中获取一个值。文件的xml如下所示:

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <boolean name="apples" value="true" />
    <boolean name="grapes" value="true" />
    <boolean name="oranges" value="true" />
</map>

文件名为fruits.xml

如何在shell脚本中使用xmllint来检索grapes的值


我尝试了
xmllint-fruits.xml
,然后又尝试了
xmllint-xpath-map/grapes
,但它不起作用。我希望最终的输出是“真的”,因为这是葡萄的价值

xmllint中此选项的正确名称为
--xpath
,路径表达式周围必须有引号(
):

$ xmllint --xpath "string(/map/boolean[@name = 'grapes']/@value)" fruit.xml
true
如果使用的是
/map/boolean[@name='grapes']/@value
,而周围没有字符串函数,xmllint将返回整个属性:
value=“true”

如果您不确定某个选项,只需键入

$ xmllint
没有任何参数。这将显示帮助和列表,以及其他内容:

--xpath表达式:计算xpath表达式,imple--noout

我在Mac OS X上,使用以下版本的xmllint:

$ xmllint --version
xmllint: using libxml version 20902
map/boolean[@name=“grapes”]/@value