获得基于从XML父标签的子标签 [英] getting the child tag based on parent tag from xml

查看:713
本文介绍了获得基于从XML父标签的子标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

家伙我有以下XML

<Point scount ="1">
  <Image name="app.png" />
</Point>

我需要解析这样的首先是XML我需要到该&LT;点&GT; ,然后在我需要选择&LT ;图像方式&gt; 标签

I need to parse the xml like this First i need to goto that <Point> and then in that i need to pick the <image> tag.

该怎么做,现在我从获取图像标记值这个样子。

how to do that, now i am fetching the value from image tag like this.

NodeList image = doc.getElementsByTagName("Image");
String imagess = ((Element)image.item(imageindex)).getAttribute("name");

如何达致这...

how to acheive this...

推荐答案

请试试这个

NodeList image = doc.getElementsByTagName("Point");
    Node singleTerminalNode = image.item(i);
            Element firstLevel = (Element)singleTerminalNode;
            NodeList value1Nodes = (firstLevel).getElementsByTagName("Image");
            imagess = ((Element)value1Nodes.item(imageindex)).getAttribute("name");

这篇关于获得基于从XML父标签的子标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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