title: Handling Xml namespaces with XmlPullParser
body: <p>Here I am using <code>XmlPullParser</code> to parse the document below.  It does not work because of the namespaces, how do I parse with namespaces?</p>
  
  <pre><code>XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  factory.setNamespaceAware(true);
  factory.setValidating(true);
  XmlPullParser xpp = factory.newPullParser();
  
  xpp.setInput(in, HTTP.UTF_8);
  String namespace = xpp.getNamespace();
  
  boolean inMessage = false;
  
  int eventType = xpp.getEventType();
  while (eventType != XmlPullParser.END_DOCUMENT) {
      //START TAGS
      if(eventType == XmlPullParser.START_TAG) {
          if(xpp.getName().equals(namespace+"resource")) {
              httpCode = Integer.valueOf( xpp.getAttributeValue(null, "code").trim() );
              type = xpp.getAttributeValue(null, "type").trim();
          } else if(xpp.getName().equals(namespace+"message")) {
              inMessage = true;
          }
      //TAG TEXT
      } else if(eventType == XmlPullParser.TEXT) {
          if(inMessage) {
              message = xpp.getText().trim();
              break; //CANCEL the iteration
          }
      } else if(eventType == XmlPullParser.END_TAG) {
          if(inMessage) {
              inMessage = false;
          }
      }
      eventType = xpp.next();
  }
  </code></pre>
  
  <p>Here is an example of the sort of document I want to parse</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;res:resource 
          xmlns:res="http://www.example.com/ns/server/resource"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://www.example.com/ns/server/resource resource.xsd "
          version="1" &gt;
      &lt;res:message httpCode="200" type="ok" &gt;
          &lt;![CDATA[Sample Success Response]]&gt;
      &lt;/res:message&gt;
      &lt;dif:person 
          xmlns:dif="http://www.example.com/ns/server/resource"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://www.example.com/ns/server/person person.xsd "
          version="1" &gt;
          &lt;dif:name&gt;test name&lt;/dif:name&gt;
          &lt;dif:description lang="en"&gt;test description&lt;/dif:description&gt;
      &lt;/dif:person &gt;
  &lt;/res:resource&gt;
  </code></pre>
  
  <p>I want to parse <code>res</code> and <code>dif</code> separately.</p>