【发布时间】:2012-08-14 05:37:33
【问题描述】:
在此我正在使用 DOM 解析器解析一个 xml 文件,该解析器将 dom1 作为解析后的文档。 问题是我想在此之后创建 UI,但我无法相同,因为我找不到相同的逻辑,请帮助我。这也给了我错误 getLength() em> 值。有什么问题??
xml 在这个链接中:
http://nchc.dl.sourceforge.net/project/trialxml/options.xml
//this is function is called when i click my button
public void next123(View view){
Element root=dom1.getDocumentElement();
NodeList nodes=root.getChildNodes();
create_Menu(nodes);
}
public void create_Menu(NodeList nodes){
for(int i=0;i<nodes.getLength();i++){
Node node=nodes.item(i);
if(node instanceof Element){
Element child = (Element)node;
String name=getTextValue(child,"Name");
String typ=child.getAttribute("type");
if(name!=null){
z++;
Log.i(TAG,"Names are:= " +name+ " -> "+typ +" -> "+ z+ " -> "+ i);
NodeList nod=child.getChildNodes();
Log.i(TAG,"Length : "+nod.getLength());
create_Menu(nod);
Log.i(TAG,"end");
}
}
}
}
在此之后我必须创建一个 UI,因为我使用 ListView 和一个 ArrayList 数组来存储我的值。问题是我必须指定一个否。到每个级别,
例如如果我的数组是test[],那么
test[0]-> main,
test[1]->1L1,1L2,1L3,
test[2]->2L1,
test[3]->2L2
test[4]->3L1,3L2
请参考xml。
【问题讨论】:
-
是的,这只是我的问题。但当时我没有用它来制作我的UI,然后卡住了。所以我想提供更多细节,以便我可以获得具体的帮助。
标签: java android xml-parsing