1

我正在使用Soap Serivce 获取XML格式的文本,现在我想以不同的序列化格式拆分图像标签和视频标签。

我的文字:

<Images> 
<Image ImageID="1000032" StoredFilename="42825125-8002-4d28-ba90-9889de5e4e91.jpg" ImageName="bPanda"  /></Images>
<PlayLists><PlayList PlayListID="1000005"  />
</PlayLists><PlayListVideoXrefs>
<PlayListVideoXref PlayListVideoXrefID="1000027" PlayListID="1000005" VideoID="1000006" PlayOrder="1"  />
<PlayListVideoXref PlayListVideoXrefID="1000028" PlayListID="1000005" VideoID="1000003" PlayOrder="2"  />
</PlayListVideoXrefs>

<Videos>
<Video VideoID="1000006" StoredFilename="c0739234-b844-46c9-b1b2-96b55f70e17e.mp4" VideoName="barcelona"  />
<Video VideoID="1000003" StoredFilename="50acb2ee-810a-4c32-b097-40c87d253e25.mp4" VideoName="bVideo1"  />
</Videos>

我使用正则表达式分割图像,它根本不工作:

Pattern p = Pattern.compile("<Images[^>]*>(.*?)</Images>");
Matcher m = p.matcher(_strUrl);
ArrayList<String> list_Images = new ArrayList<String>();

try {
    while (m.find()) {
        System.out.println(m.group(1));
        list_Images.add(m.group(1));

    }
} catch (Exception e) {
    // TODO: handle exception
    Toast.makeText(getApplicationContext(), e.getMessage().toString(), 1).show();
}
4

2 回答 2

0

我认为 Dom 不能为我的 XML 工作,因为图像标签包含用于显示图像的信息。我只是将图像和视频标签拆分为两个数组。对于拆分使用正则表达式,它的工作很谨慎但我想访问图像标签中的字段..例如:

<Image ImageID="1000032" **StoredFilename**="42825125-8002-4d28-ba90-9889de5e4e91.jpg" ImageName="bPanda"  /></Images>

此标记包括将其溢出到数组中的 StoredFiledname

于 2013-07-09T09:28:50.290 回答
0

要捕获该images部分,您可能需要转义正斜杠

<Images[^>]*>(.*?)<\/Images>,现场示例:http ://www.rubular.com/r/h5TZdE5nyb

要解析单个图像标记中的每个属性:

\s([^=]*)="([^"]*)",现场示例:http ://www.rubular.com/r/eiTS7cpY5p

于 2013-07-09T12:49:08.013 回答