看看:
<allChoices>
<choiceID>a</choiceID>
<choice>bbbbbbb</choice>
<choiceID>b</choiceID>
<choice>dddddddddddd</choice>
<allChoices>
与
Element e1=singleSelection.getChild("allChoices");
List allChoices=e1.getChildren();
Iterator tempa=allChoices.iterator();
while(tempa.hasNext()){
Element a1=(Element)tempa.next();
System.out.println(a1.getChild("choiceID").getText());
System.out.println(a1.getChild("choice").getText());
}
就会发现tempa有四个元素,但是....
IT人是聪明的,应该是
自己找
<allChoices>
<choiceID>a</choiceID>
<choice>bbbbbbb</choice>
<choiceID>b</choiceID>
<choice>dddddddddddd</choice>
<allChoices>
与
Element e1=singleSelection.getChild("allChoices");
List allChoices=e1.getChildren();
Iterator tempa=allChoices.iterator();
while(tempa.hasNext()){
Element a1=(Element)tempa.next();
System.out.println(a1.getChild("choiceID").getText());
System.out.println(a1.getChild("choice").getText());
}
就会发现tempa有四个元素,但是....
IT人是聪明的,应该是
自己找
解决方案 »
- java如何实现将sql脚本自动上传至服务器
- 拼接treejson数据不能显示child
- Struts2 高深问题 求高手解决
- strut2问题求解 OgnlException while setting property 'location' on type 'org.apache.struts2.dispatcher.ServletDispatcherResult'
- Hiernate在request中传递参数问题!!!急急急!!!
- ireport 输出验证问题
- ???高分求?? 金蝶面试题笔试题 北航 西电 东南 请进
- tomcat 5.5 的一个问题
- jboss的JNDI问题啊,搞了我一天时间了.帮帮忙.
- 关于Hibernate的GUI配置工具
- 用j2ee上的tomcat编译时总提示错误?关于io的,急切求解!!!
- 通过<ejb-ref>引入EJB和直接象客户端那样调用EJB有什么不同?
<choiceID>a</choiceID>
<choice>bbbbbbb</choice>
<choiceID>b</choiceID>
<choice>dddddddddddd</choice>
<allChoices>//--------></allChoices>
2.Document doc = sb.build(new FileInputStream("singleChoice.xml"));
应该具体指定xml文件的详细位置。
while(tempa.hasNext()){
Element a1=(Element)tempa.next();
System.out.println(a1.getChild("choiceID").getText());
System.out.println(a1.getChild("choice").getText());
}
->
System.out.println(e1.get(0).getText());
List allChoices=e1.getChildren();
Iterator tempa=allChoices.iterator();
while(tempa.hasNext()){
Element a1=(Element)tempa.next();
System.out.println(a1.getChild("choiceID").getText());
System.out.println(a1.getChild("choice").getText());
}
tempa 应该是:
<choiceID>a</choiceID>
<choice>bbbbbbb</choice>
<choiceID>b</choiceID>
<choice>dddddddddddd</choice>
而a1 是单一element.
怎么能: a1.getChild() 呢?! 当然是空了
<allChoices>
<choiceID>a</choiceID>
<choice>bbbbbbb</choice>
<choiceID>b</choiceID>
<choice>dddddddddddd</choice>
<allChoices>
改为
<allChoices>
<choice ID="a">bbbbbbb</choiceID>
<choice ID="b">dddddddddddd</choiceID>
<allChoices>
处理时会好一点.
个人认为:
有两个或者以上的元素组成一个整体的对像的结构建议加属性标识.
(如
<choiceID>a</choiceID>
<choice>bbbbbbb</choice>
才是一个整体)
如上面两个,请大侠指教,理论上的书没怎么看过,纯属个人思想,希望不会误导别人.
改为
<allChoices>
<choice ID="a">bbbbbbb</choice>
<choice ID="b">dddddddddddd</choice>
</allChoices>