title: How to parse xml string with xmlpullparser android
body: <p>I want to parse an XML string and display it in a EditText but I can't, I not understand what could be the problem, please a bit help, my code :</p>
  
  <p>private String xmlc = <code>"&lt;game&gt;&lt;cel&gt;5&lt;/cel&gt;&lt;val&gt;2&lt;/val&gt;&lt;/game&gt;";</code></p>
  
  <pre><code>private CharSequence readXML(String xmlc2) throws XmlPullParserException {
  
  
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      XmlPullParser xpp = factory.newPullParser();
  
      String results = "";
      String celda = "";
      String valor = "";
  
      xpp.setInput(new StringReader (xmlc2));
      int eventType = xpp.getEventType();
      String tagName = xpp.getName();
  
      try {       
          while (eventType != XmlPullParser.END_DOCUMENT) {
  
              if(tagName.equalsIgnoreCase("cell")){
                  celda = xpp.nextText();
              } else if(tagName.equalsIgnoreCase("val")){
                  valor = xpp.nextText();
              }       
              xpp.nextTag();      
          }       
      } catch (Exception e) {
          Toast.makeText(this, "error!", Toast.LENGTH_LONG).show();
      }
      return celda;
  }
  </code></pre>
  
  <hr>
  
  <p>Thanks for the suggestion, now I can send the string xml as parameter and I can to parse, but I don't know how save the 2 values found and show each value in different EditText? </p>
  
  <pre><code>private EditText et02;
  private EditText et03;
  private String xmlc = "&lt;game&gt;&lt;cel&gt;5&lt;/cel&gt;&lt;val&gt;2&lt;/val&gt;&lt;/game&gt;";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      EditText et02 = (EditText)findViewById(R.id.et02);
      EditText et03 = (EditText)findViewById(R.id.et03);
  
      TextView myXmlContent = (TextView)findViewById(R.id.xml_tv);
      String stringXmlContent;
  
      stringXmlContent = getAllXML();
      myXmlContent.setText(stringXmlContent);
  
  }
  public String getAllXML(){
  
      Activity activity = this;
      String str = "";
  
      //For file source
      //Resources res = activity.getResources();
      //XmlResourceParser xpp = res.getXml(R.xml.test);
  
  
      try {
          //For String source
          XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
          factory.setNamespaceAware(true);
          XmlPullParser xpp = factory.newPullParser();
          xpp.setInput(new StringReader(xmlc)); 
  
          xpp.next();
          int eventType = xpp.getEventType();                        
  
            while (xpp.getEventType()!=XmlPullParser.END_DOCUMENT) {
                if (xpp.getEventType()==XmlPullParser.START_TAG) {
                    if (xpp.getName().equals("cel")) {
                        str += "\ncell : "+xpp.nextText();
                    }
                    if (xpp.getName().equals("val")) {
                        str += "\nval : "+xpp.nextText();                       
                    }
                }
                xpp.next();
            }
  
      } catch (XmlPullParserException e) {
            e.printStackTrace();
      } catch (IOException e) {
            e.printStackTrace();
      }
      return str;
  }
  </code></pre>