提取的Andr​​oid XML标记之间的字符串,不解析XML [英] Extract string between xml tags in android without parsing the xml

查看:107
本文介绍了提取的Andr​​oid XML标记之间的字符串,不解析XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的XML是这样的:

I have a very simple XML like this:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://icacec.com/">TRUE,Hrithik Sharma,201301-11</string>

现在,我想只提取 TRUE 赫里尼克·夏尔马 201301-11 3个独立的变量

Now, I want to extract only TRUE, Hrithik Sharma, 201301-11 in 3 separate variables.

我可以根据分割字符串在是这样的:

I could split the string based on the "," like this:

String[] parts = responseBody.split(",");
String response_auth = parts[0];
String user_name = parts[1];    
String user_number=parts[2];

不过,这是我现在面临的问题是,字符串没有得到独立提取。为了更precise,没有XML标记。我应该如何实现呢?

But the problem which I am facing is that, the Strings are not getting extracted independently. To be more precise, without the XML tags. How should I achieve that?

推荐答案

这可以解决,但没有解析你有什么打算与其他条件做这个简单的例子?

This could solve this simple case, but without parsing what are you going to do with other conditions?

public static void main(String[] args) {
    String raw = "<string xmlns=\"http://icacec.com/\">TRUE,Hrithik Sharma,201301-11</string>";
    raw = raw.substring(0, raw.lastIndexOf("<"));
    raw = raw.substring(raw.lastIndexOf(">") + 1, raw.length());
    String [] contents = raw.split(",");
    for (String txt : contents)
        System.out.println(txt);
}

这篇关于提取的Andr​​oid XML标记之间的字符串,不解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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