看看:
<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人是聪明的,应该是
自己找

解决方案 »

  1.   

    1.  allChoices>
             <choiceID>a</choiceID>
             <choice>bbbbbbb</choice>  
             <choiceID>b</choiceID>
             <choice>dddddddddddd</choice>
          <allChoices>//--------></allChoices>
    2.Document doc = sb.build(new FileInputStream("singleChoice.xml"));
       应该具体指定xml文件的详细位置。    
      

  2.   

    太阳雨,你是不是说我的那个<allChoices>的结束符写错了,我改了过来,改为了</allChoices>也出现相同的错误,到底划什么原因呢?麻烦你告诉我吧,非常感谢。:)
      

  3.   

    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());
               }
    ->
     System.out.println(e1.get(0).getText());
      

  4.   

    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 应该是:
    <choiceID>a</choiceID>
             <choice>bbbbbbb</choice>  
             <choiceID>b</choiceID>
             <choice>dddddddddddd</choice>
    而a1 是单一element.
    怎么能: a1.getChild() 呢?! 当然是空了
      

  5.   

    本身这样的结构不是很好处理,
    <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>
    才是一个整体)
    如上面两个,请大侠指教,理论上的书没怎么看过,纯属个人思想,希望不会误导别人.
      

  6.   

    上面的有点笔误,不好意思
    改为
    <allChoices>
             <choice ID="a">bbbbbbb</choice>
             <choice ID="b">dddddddddddd</choice>
    </allChoices>