怎么办XPath或XML解析Android中 [英] How to do XPath or XML parsing in Android

查看:112
本文介绍了怎么办XPath或XML解析Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含表单的XML字符串变量:

 <项目>
    < descriptin> ABC< /描写的特征>
    <标题>&高清LT; /标题>
< /项目>

我要显示在列表视图标题的文本的,但是当我用我得到的XML:

 一个String = hitdoc.get(文本)

我在android系统与Lucene搜索工作是否有帮助。


解决方案

  

我要显示的标题的文本


您需要评估的XPath前pression像

  /项目/标题/文本()

这选择任何文本节点(在你的情况只是一个单一的一个)这是一个标题的子名为顶级元素的子项目

也可以直接得到字符串,评估这个XPath前pression

 字符串(/项目/标题)

I have string variable which contains XML of the form:

<item>
    <descriptin>abc</descripton>
    <title>def</title>
</item> 

I want to the display the title text in a listview but I'm getting XML when I use:

String s=hitdoc.get("text")

I'm working with Lucene search in android if that helps.

解决方案

I want to the display the title text

You need to evaluate an XPath expression like:

/item/title/text()

this selects any text node (in your case just a single one) that is a child of a title that is a child of the top element named item

Or, to get the string directly, evaluate this XPath expression:

string(/item/title)

这篇关于怎么办XPath或XML解析Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆