Java 为什么XML属性不能在2.2.1和2.3中显示?

Java 为什么XML属性不能在2.2.1和2.3中显示?,java,android,xml,Java,Android,Xml,请注意,我对JAVA和Android非常陌生,谢谢 我正在读取一个Xml文件: <question1 question="Que Grupo de los 80 Interpreta este Exito 1" answer="Esto esta la repuesta correcta 01" opt1="opcion1" opt2="opcion2" opt3="opcion2" youtubevideo="ID vide de youtube1" mp3="mp3 file1"/&g

请注意,我对JAVA和Android非常陌生,谢谢

我正在读取一个Xml文件:

<question1 question="Que Grupo de los 80 Interpreta este Exito 1" answer="Esto esta la repuesta correcta 01" opt1="opcion1" opt2="opcion2" opt3="opcion2" youtubevideo="ID vide de youtube1" mp3="mp3 file1"/>

我不确定你是否还需要它,但我也遇到了同样的麻烦

解决方案:所有
getAttributeValue()
内容必须在
START\u标记
case中,因为所有属性都存储在START标记中。它出现在android V2.3中

public void ReadXml(InputStream xmlFile) throws IOException, XmlPullParserException{

    try {
        XmlPullParserFactory pullParserFactory = XmlPullParserFactory.newInstance();
        parser = pullParserFactory.newPullParser();

        ///    InputStream in_s = getApplicationContext().getAssets().open("test1.xml");
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
            parser.setInput(xmlFile, null);

         //  parseXML(parser);

    } catch (XmlPullParserException e) {

        e.printStackTrace();
    }

    int event = 0;
    try {
        event = parser.getEventType();
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    while (event != XmlPullParser.END_DOCUMENT) 
    {
       String name=parser.getName();
       switch (event){
          case XmlPullParser.START_TAG:
          break;
          case XmlPullParser.END_TAG:

            if(this.currQuestiong==1){  
                if(name.equals("question1")){

                    this.que1= parser.getAttributeValue(null,"opt1");
                    this.que2= parser.getAttributeValue(null,"opt2");
                    this.que3= parser.getAttributeValue(null,"opt3");                       
                    this.correctAnswer= parser.getAttributeValue(null,"answer");
                    this.question= parser.getAttributeValue(null,"question");
                //    skip(parser);
              break;

                }
            }

            if(this.currQuestiong==2){  
                if(name.equals("question2")){

                    this.que1= parser.getAttributeValue(null,"opt1");
                    this.que2= parser.getAttributeValue(null,"opt2");
                    this.que3= parser.getAttributeValue(null,"opt3");
                    this.correctAnswer= parser.getAttributeValue(null,"answer");
                    this.question= parser.getAttributeValue(null,"question");
                   // skip(parser);
              break;      

                }
            }



            if(this.currQuestiong==3){  
                if(name.equals("question3")){

                    this.que1= parser.getAttributeValue(null,"opt1");
                    this.que2= parser.getAttributeValue(null,"opt2");
                    this.que3= parser.getAttributeValue(null,"opt3");
                    this.correctAnswer= parser.getAttributeValue(null,"answer");
                    this.question= parser.getAttributeValue(null,"question");
                  //  skip(parser);
              break;
                }
            }



            if(this.currQuestiong==4){  
                if(name.equals("question4")){

                    this.que1= parser.getAttributeValue(null,"opt1");
                    this.que2= parser.getAttributeValue(null,"opt2");
                    this.que3= parser.getAttributeValue(null,"opt3");
                    this.correctAnswer= parser.getAttributeValue(null,"answer");
                    this.question= parser.getAttributeValue(null,"question");
                   // skip(parser);
              break;
                }
            }


            if(this.currQuestiong==5){  
                if(name.equals("question5")){

                    this.que1= parser.getAttributeValue(null,"opt1");
                    this.que2= parser.getAttributeValue(null,"opt2");
                    this.que3= parser.getAttributeValue(null,"opt3");
                    this.correctAnswer= parser.getAttributeValue(null,"answer");
                    this.question= parser.getAttributeValue(null,"question");
                   // skip(parser);
              break;
                }
            }

            if(this.currQuestiong==6){  
                if(name.equals("question6")){

                    this.que1= parser.getAttributeValue(null,"opt1");
                    this.que2= parser.getAttributeValue(null,"opt2");
                    this.que3= parser.getAttributeValue(null,"opt3");                       
                    this.correctAnswer= parser.getAttributeValue(null,"answer");
                    this.question= parser.getAttributeValue(null,"question");
                     break;
                }
            }


            if(this.currQuestiong==7){  
                if(name.equals("question7")){

                    this.que1= parser.getAttributeValue(null,"opt1");
                    this.que2= parser.getAttributeValue(null,"opt2");
                    this.que3= parser.getAttributeValue(null,"opt3");
                    this.correctAnswer= parser.getAttributeValue(null,"answer");
                    this.question= parser.getAttributeValue(null,"question");
                   // skip(parser);


                }
            }



            if(this.currQuestiong==8){  
                if(name.equals("question8")){

                    this.que1= parser.getAttributeValue(null,"opt1");
                    this.que2= parser.getAttributeValue(null,"opt2");
                    this.que3= parser.getAttributeValue(null,"opt3");
                    this.correctAnswer= parser.getAttributeValue(null,"answer");
                    this.question= parser.getAttributeValue(null,"question");
                  //  skip(parser);
              break;
                }
            }



            if(this.currQuestiong==9){  
                if(name.equals("question9")){

                    this.que1= parser.getAttributeValue(null,"opt1");
                    this.que2= parser.getAttributeValue(null,"opt2");
                    this.que3= parser.getAttributeValue(null,"opt3");
                    this.correctAnswer= parser.getAttributeValue(null,"answer");
                    this.question= parser.getAttributeValue(null,"question");
                   // skip(parser);
                    break;
                }
            }


            if(this.currQuestiong==10){  
                if(name.equals("question10")){

                    this.que1= parser.getAttributeValue(null,"opt1");
                    this.que2= parser.getAttributeValue(null,"opt2");
                    this.que3= parser.getAttributeValue(null,"opt3");
                    this.correctAnswer= parser.getAttributeValue(null,"answer");
                    this.question= parser.getAttributeValue(null,"question");
                   // skip(parser);
                    break;
                }
            }
      break;
       }         
       try {
        event = parser.next();
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }                   
    }


}