想遍历xml文件的,但是在if的时候得到结果后还会继续执行else中的getSelectionNode,为什么?
public Node getSelectionNode(NodeList soList, ComponentItem componentItem) {
String name = null;
String iconName = null;
Node node = null;
Node categoryNode = null;
if (soList != null) {
for (int i = 0; i < soList.getLength(); i++) {
categoryNode = soList.item(i);
Element categoryElement = null;
if (categoryNode instanceof Element) {
categoryElement = (Element) categoryNode;
name = categoryElement.getAttribute(NAME_ATTRIBUTE);
iconName = categoryElement.getAttribute(ICON_ATTRIBUTE);
if (name.equals(componentItem.getName())
&& iconName.equals(componentItem.getIconName())) {
String parentname = ((Element) (categoryElement
.getParentNode())).getAttribute(NAME_ATTRIBUTE);
if (parentname != null
&& parentname.equals(componentItem.getParent())) {
node = categoryNode;
break;
}
} else {
getSelectionNode(categoryNode.getChildNodes(),
componentItem);
}
}
}
}
return node;
}
public Node getSelectionNode(NodeList soList, ComponentItem componentItem) {
String name = null;
String iconName = null;
Node node = null;
Node categoryNode = null;
if (soList != null) {
for (int i = 0; i < soList.getLength(); i++) {
categoryNode = soList.item(i);
Element categoryElement = null;
if (categoryNode instanceof Element) {
categoryElement = (Element) categoryNode;
name = categoryElement.getAttribute(NAME_ATTRIBUTE);
iconName = categoryElement.getAttribute(ICON_ATTRIBUTE);
if (name.equals(componentItem.getName())
&& iconName.equals(componentItem.getIconName())) {
String parentname = ((Element) (categoryElement
.getParentNode())).getAttribute(NAME_ATTRIBUTE);
if (parentname != null
&& parentname.equals(componentItem.getParent())) {
node = categoryNode;
break;
}
} else {
getSelectionNode(categoryNode.getChildNodes(),
componentItem);
}
}
}
}
return node;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货