Problem parsing xml file with SAXParser

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Problem parsing xml file with SAXParser

Postby YoFrankie » Sat Jan 02, 2010 1:57 am

To parse a xml file with SAX Parser, I extend the defaultHandler:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyXMLParser extends DefaultHandler {
  2.  
  3.  
  4.  
  5.         public MyXMLParser () {
  6.  
  7.                 super();
  8.  
  9.         }
  10.  
  11.  
  12.  
  13.         public void startElement(String namespaceURI, String name, String qName,
  14.  
  15.                         Attributes atts) throws SAXException {
  16.  
  17.               if(name.equals("name"){
  18.  
  19.                    android.util.Log.d("name",atts.getValue("full");
  20.  
  21.                    android.util.Log.d("name",atts.getValue("new:bla"); //doesn't work
  22.  
  23.                    android.util.Log.d("name",atts.getValue("bla");        //doesn't work
  24.  
  25.                    android.util.Log.d("name",atts.getValue("new");      //doesn't work
  26.  
  27.               }
  28.  
  29.         }
  30.  
  31.  
  32.  
  33.         public void endElement(String uri, String name, String qName)
  34.  
  35.                         throws SAXException {
  36.  
  37.                        
  38.  
  39.         }
  40.  
  41.  
  42.  
  43.         public void characters(char ch[], int start, int length) {
  44.  
  45.        
  46.  
  47.         }
  48.  
  49.  
  50.  
  51. }
  52.  
  53.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


text xml:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <name full="YoFrankie" new:bla="Yo"></name>
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


I can get the full attribute easily but how to get the new:bla attribute?
YoFrankie
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Aug 03, 2009 4:52 pm

Top

Re: Problem parsing xml file with SAXParser

Postby jagtap.jj1 » Wed Jan 13, 2010 3:33 pm


Try by this way
AttributesImpl mAttributesImpl = new AttributesImpl(atts);
String mValue= mAttributesImpl.getValue("new:bla");

import org.xml.sax.helpers.AttributesImpl;

i.e.
f(name.equals("name")
{
AttributesImpl mAttributesImpl = new AttributesImpl(atts);
String mValue = mAttributesImpl.getValue("new:bla");
android.util.Log.d("name", mValue);
}

java-android developer
User avatar
jagtap.jj1
Senior Developer
Senior Developer
 
Posts: 124
Joined: Fri Aug 22, 2008 11:52 am
Location: India(Mumbai)

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests