[英]Search for XML attribute with another attribute in Android
I am currently trying to search a local XML File to retrieve a certain attribute, my search key is also another attribute. 我目前正在尝试搜索本地XML文件以检索某个属性,我的搜索键也是另一个属性。
My XML is like this: 我的XML是这样的:
<JPPlatforms>
<Platform PlatformTag="2980" PlatformNo="47280">
</Platform>
<JPPlatforms>
I want to search the 1000 or so lines for the PlatformNo 47280 and return the PlatformTag 2980. 我想在1000左右的行中搜索PlatformNo 47280,然后返回PlatformTag 2980。
How would I implement this in Java for Android? 如何在Java for Android中实现此功能? Should I use an XMLPullParser is there something more efficient to find and return one particular value in XML? 我应该使用XMLPullParser吗?在XML中找到并返回一个特定值是否有更有效的方法?
This is trivial if you can use XPath : 如果可以使用XPath,那么这很简单:
//Platform[@PlatformNo=47280]/@PlatformTag
Explanation : 说明:
//Platform
: find Platform
element, anywhere in the XML document... //Platform
:在XML文档中的任何位置查找Platform
元素... [@PlatformNo=47280]
: ...where PlatformNo
attribute value equals 47280
[@PlatformNo=47280]
:...其中PlatformNo
属性值等于47280
/@PlatformTag
: from such Platform
, return PlatformTag
attribute /@PlatformTag
:从这样的Platform
,返回PlatformTag
属性 I haven't used XPath in Android, but it seem possible according to this thread : Search in XML File with XPath in Android 我没有在Android中使用XPath,但是根据此线程似乎可行: 在Android中使用XPath在XML文件中搜索
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.