title: Kxml parsing in android
body: <p>Hi i used kxml jar for parsing data from web service.I used previously in other project..But now i am using the same in new project,,but i am receiving error i cant able to troubleshoot it..</p>
  
  <p>My xml file will look like this:</p>
  
  <pre><code>&lt;rss version="2.0"&gt;
  
  &lt;tttt&gt;gsdsj&lt;/tttt&gt;
  &lt;dddd&gt;urkjrnf&lt;/dddd&gt;
  &lt;item&gt;
  &lt;title&gt;ghsdsjhdsjdb&lt;/title&gt;
  &lt;description&gt;fgdhshbsdb&lt;/description&gt;
  &lt;/item&gt;
  
  &lt;item&gt;
  &lt;title&gt;ghsdsjhdsjdb&lt;/title&gt;
  &lt;description&gt;fgdhshbsdb&lt;/description&gt;
  &lt;/item&gt;
  
  &lt;item&gt;
  &lt;title&gt;ghsdsjhdsjdb&lt;/title&gt;
  &lt;description&gt;fgdhshbsdb&lt;/description&gt;
  &lt;/item&gt;
  
  &lt;/rss&gt;
  </code></pre>
  
  <p>I want o get that title.</p>
  
  <p>My parser file is:</p>
  
  <pre><code>public class TaplistingParser 
  {
      public TaplistingParser()
      {
  
      }
  
      public String getXmlFromUrl(String url)
      {
          String xml=null;
          DefaultHttpClient httpclient=new DefaultHttpClient();
          HttpPost httpPost=new HttpPost(url);
          try 
          {
              HttpResponse httpresponse = httpclient.execute(httpPost);
              HttpEntity httpentity=httpresponse.getEntity();
              xml=EntityUtils.toString(httpentity);
          } 
          catch (ClientProtocolException e) 
          {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } 
          catch (IOException e) 
          {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  //      System.out.println("xml="+xml);
          return xml;
      }
  
      public Document getDomElement(String xml)
      {
          Document doc=null;
          DocumentBuilderFactory dbf= DocumentBuilderFactory.newInstance();
          dbf.setCoalescing(true);
          try 
          {
              DocumentBuilder db= dbf.newDocumentBuilder();
  
              InputSource is= new InputSource();
              is.setCharacterStream(new StringReader(xml));
              try {
                  doc=db.parse(is);
              } catch (SAXException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          } 
          catch (ParserConfigurationException e) 
          {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }       
          return doc;
  
      }
  
       public final String getElementValue( Node elem ) {
           Node child;
           if( elem != null){
               if (elem.hasChildNodes()){
                   for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
  //                   if( child.getNodeType() == Node.TEXT_NODE  ){
                           return child.getNodeValue();
  //                   }
                   }
               }
           }
           return "";
       }
  
       /**
        * Getting node value
        * @param Element node
        * @param key string
        * */
       public String getValue(Element item, String str) {     
              NodeList n = item.getElementsByTagName(str);        
              return this.getElementValue(n.item(0));
          }
  }
  </code></pre>
  
  <p>My activity code:</p>
  
  <pre><code>public void getelement()
      {
  
         TaplistingParser parser = new TaplistingParser();
         String xml= parser.getXmlFromUrl(URL);
         Document doc=parser.getDomElement(xml);        
  
         NodeList nl=doc.getElementsByTagName("item");
         title = new String[nl.getLength()];      
  
         for(int i=0; i &lt; nl.getLength(); i++ )
         {
  
          Element e = (Element) nl.item(i);
          title[i]=parser.getValue(e, "title");                       
         }   
  
      }
  </code></pre>
  
  <p>my logcat is:</p>
  
  <pre><code>12-11 15:58:42.962: W/System.err(551): org.xml.sax.SAXParseException: expected: /META read: HEAD (position:END_TAG &lt;/HEAD&gt;@11:8 in java.io.StringReader@44c60e80) 
  12-11 15:58:42.982: W/System.err(551):  at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:151)
  12-11 15:58:42.992: W/System.err(551):  at parser.TaplistingParser.getDomElement(TaplistingParser.java:67)
  12-11 15:58:42.992: W/System.err(551):  at your.com.font.FontActivity.getelement(FontActivity.java:42)
  12-11 15:58:43.023: W/System.err(551):  at your.com.font.FontActivity.onCreate(FontActivity.java:25)
  12-11 15:58:43.032: W/System.err(551):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  12-11 15:58:43.032: W/System.err(551):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
  12-11 15:58:43.032: W/System.err(551):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
  12-11 15:58:43.042: W/System.err(551):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
  12-11 15:58:43.042: W/System.err(551):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
  12-11 15:58:43.042: W/System.err(551):  at android.os.Handler.dispatchMessage(Handler.java:99)
  12-11 15:58:43.042: W/System.err(551):  at android.os.Looper.loop(Looper.java:123)
  12-11 15:58:43.042: W/System.err(551):  at android.app.ActivityThread.main(ActivityThread.java:4363)
  12-11 15:58:43.042: W/System.err(551):  at java.lang.reflect.Method.invokeNative(Native Method)
  12-11 15:58:43.042: W/System.err(551):  at java.lang.reflect.Method.invoke(Method.java:521)
  12-11 15:58:43.042: W/System.err(551):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  12-11 15:58:43.042: W/System.err(551):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  12-11 15:58:43.052: W/System.err(551):  at dalvik.system.NativeStart.main(Native Method)
  12-11 15:58:43.052: D/AndroidRuntime(551): Shutting down VM
  12-11 15:58:43.052: W/dalvikvm(551): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
  12-11 15:58:43.062: E/AndroidRuntime(551): Uncaught handler: thread main exiting due to uncaught exception
  12-11 15:58:43.072: E/AndroidRuntime(551): java.lang.RuntimeException: Unable to start activity ComponentInfo{your.com.font/your.com.font.FontActivity}: java.lang.NullPointerException
  12-11 15:58:43.072: E/AndroidRuntime(551):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at android.os.Handler.dispatchMessage(Handler.java:99)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at android.os.Looper.loop(Looper.java:123)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at android.app.ActivityThread.main(ActivityThread.java:4363)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at java.lang.reflect.Method.invokeNative(Native Method)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at java.lang.reflect.Method.invoke(Method.java:521)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at dalvik.system.NativeStart.main(Native Method)
  12-11 15:58:43.072: E/AndroidRuntime(551): Caused by: java.lang.NullPointerException
  12-11 15:58:43.072: E/AndroidRuntime(551):  at your.com.font.FontActivity.getelement(FontActivity.java:44)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at your.com.font.FontActivity.onCreate(FontActivity.java:25)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  12-11 15:58:43.072: E/AndroidRuntime(551):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
  12-11 15:58:43.072: E/AndroidRuntime(551):  ... 11 more
  12-11 15:58:43.102: I/dalvikvm(551): threadid=7: reacting to signal 3
  12-11 15:58:43.202: I/dalvikvm(551): Wrote stack trace to '/data/anr/traces.txt'
  </code></pre>
  
  <p>Thanks in advance..</p>