Parsing XML from the Net - Using the SAXParser

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby kali » Tue Jun 02, 2009 11:19 am

hallo padde
i am trying to parse xml file my xml file is like

<categories>
<category name="Art"/>
<category name="Business"/>

</categories>

but i get error i have done same procedure as you have done

pls help me.
kali
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Tue Jan 27, 2009 1:31 pm

Top

Postby padde » Tue Jun 02, 2009 3:43 pm

Could you be more specific error wise? :)
And a full example of the XML you try to parse would help too.

greets Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby kali » Wed Jun 03, 2009 7:46 am

hello padde first of al thanks to reply,
my XML file is like this

<categories>
<category id="1" name="Art"/>
<category id="2" name="Business"/>
<category id="3" name="Celebrities"/>
</categories>

i want to fatch name of category(Art,Business,Celebrities) and want to display it on output

for this application what i should write in my ContentHandler class perticulaly for startElement() and endElement() method

my startElement() method is like this

public void startElement(String n, String l, String q, Attributes a) {
switch(Tags.valueOf(l)) {
case categories:
in_category = true;
break;
case category:
if(in_category)
DataSet.setCategoryname(a.getValue("name"));
break;
}
}

when debugger comes over line
in_category = true;
without going on BREAK statement it just comes out with
error:"Source not found"

pls relply me
kali
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Tue Jan 27, 2009 1:31 pm

Postby padde » Wed Jun 03, 2009 8:31 am

cant find a error so far in your code...

is this line the first one in your XML?
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0"?>
  2.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


if not put it there.. not till then the parser accept the file as XML file


Greets Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby Mr_Tremor » Sun Jun 07, 2009 10:19 pm

I believe the reason you are getting an error is because you need to be setting:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.in_category = true;
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


kali wrote:hello padde first of al thanks to reply,
my XML file is like this

<categories>
<category id="1" name="Art"/>
<category id="2" name="Business"/>
<category id="3" name="Celebrities"/>
</categories>

i want to fatch name of category(Art,Business,Celebrities) and want to display it on output

for this application what i should write in my ContentHandler class perticulaly for startElement() and endElement() method

my startElement() method is like this

public void startElement(String n, String l, String q, Attributes a) {
switch(Tags.valueOf(l)) {
case categories:
in_category = true;
break;
case category:
if(in_category)
DataSet.setCategoryname(a.getValue("name"));
break;
}
}

when debugger comes over line
in_category = true;
without going on BREAK statement it just comes out with
error:"Source not found"

pls relply me
Mr_Tremor
Developer
Developer
 
Posts: 26
Joined: Tue Jun 02, 2009 6:35 pm

Postby kali » Mon Jun 08, 2009 9:18 am

hello padde,Mr_Tremor
first of all thanks to reply me
firends there is good news i solve my error and get the result i want
thanks evey one to reply me.
thanks.
kali
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Tue Jan 27, 2009 1:31 pm

Top

Re: Parsing XML from the Net - Using the SAXParser

Postby desuvinodkumar » Tue Jun 16, 2009 12:58 pm

How can i query the web services (nusop)

ineed the information oabout webservices

thanks in advance
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

Hi

Postby androiddev53 » Wed Jun 17, 2009 4:19 am

hi
even I am facing same XML problem <mytag>anddev.org rulez=)</mytag> doesn't work on android1.5.
can anybody help me with it?

Thanks & Regards,
androiddev53
androiddev53
Freshman
Freshman
 
Posts: 4
Joined: Tue May 19, 2009 2:14 pm

Postby myster23 » Thu Jul 02, 2009 7:18 am

If I use the textual code from: http://www.anddev.org/parsing_xml_from_ ... 3-s15.html in an Android project will the Eclipse connect the Url url=new URL("http://www.anddev.org/images/tut/basic/parsingxml/example.xml"); automattically ? or it needs something else before this to establish the connection from Eclipse ?
myster23
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Apr 23, 2009 7:53 am

Postby arams » Fri Jul 03, 2009 8:59 am

Hello myster23

If we use web api in parsing XML file then add permission in android manifeast file


<uses-permission android:name="android.permission.INTERNET" />

else
if u have some other error ?post it
arams
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Fri May 08, 2009 7:45 am

Postby arams » Fri Jul 03, 2009 9:14 am

am got the output by using the following codes....

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.sample;
  2. import org.xml.sax.Attributes;
  3. import org.xml.sax.SAXException;
  4. import org.xml.sax.helpers.DefaultHandler;
  5.  
  6.  
  7. public class ExampleHandler extends DefaultHandler{
  8.  
  9.      // ===========================================================
  10.      // Fields
  11.      // ===========================================================
  12.      
  13.      private boolean in_outertag = false;
  14.      private boolean in_innertag = false;
  15.      private boolean in_mytag = false;
  16.      
  17.      private ParsedExampleDataSet myParsedExampleDataSet =new ParsedExampleDataSet();
  18.  
  19.      // ===========================================================
  20.      // Getter & Setter
  21.      // ===========================================================
  22.  
  23.      public ParsedExampleDataSet getParsedData() {
  24.           return this.myParsedExampleDataSet;
  25.      }
  26.  
  27.      // ===========================================================
  28.      // Methods
  29.      // ===========================================================
  30.      @Override
  31.      public void startDocument() throws SAXException {
  32.          // this.myParsedExampleDataSet = new ParsedExampleDataSet();
  33.      }
  34.  
  35.      @Override
  36.      public void endDocument() throws SAXException {
  37.           // Nothing to do
  38.      }
  39.  
  40.      /** Gets be called on opening tags like:
  41.       * <tag>
  42.       * Can provide attribute(s), when xml was like:
  43.       * <tag attribute="attributeValue">*/
  44.      @Override
  45.      public void startElement(String namespaceURI, String localName,
  46.                String qName, Attributes atts) throws SAXException {
  47.           if (localName.equals("outertag")) {
  48.                this.in_outertag = true;
  49.           }else if (localName.equals("innertag")) {
  50.                  
  51.                this.in_innertag = true;
  52.                String innerValue=atts.getValue("sampleattribute");
  53.                myParsedExampleDataSet.setExtractedAttr(innerValue);
  54.                
  55.           }else if (localName.equals("mytag")) {
  56.                  
  57.                this.in_mytag = true;
  58.                //myParsedExampleDataSet.setExtractedString();
  59.           }else if (localName.equals("tagwithnumber")) {
  60.                // Extract an Attribute
  61.                String attrValue = atts.getValue("thenumber");
  62.                int i = Integer.parseInt(attrValue);
  63.                myParsedExampleDataSet.setExtractedInt(i);
  64.           }
  65.      }
  66.      
  67.      /** Gets be called on closing tags like:
  68.       * </tag> */
  69.      @Override
  70.      public void endElement(String namespaceURI, String localName, String qName)
  71.                throws SAXException {
  72.           if (localName.equals("outertag")) {
  73.                this.in_outertag = false;
  74.           }else if (localName.equals("innertag")) {
  75.                this.in_innertag = false;
  76.           }else if (localName.equals("mytag")) {
  77.                this.in_mytag = false;
  78.           }else if (localName.equals("tagwithnumber")) {
  79.                // Nothing to do here
  80.           }
  81.      }
  82.      
  83.      /** Gets be called on the following structure:
  84.       * <tag>characters</tag> */
  85.      //@Override
  86.     public void characters(char ch[], int start, int length) {
  87.           if(this.in_mytag){
  88.                   //ch="lihhkjhkjhk".toCharArray();
  89.           myParsedExampleDataSet.setExtractedString(new String(ch, 0, ch.length));
  90.      }
  91.     }
  92. }
  93.  
Parsed in 0.044 seconds, using GeSHi 1.0.8.4



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.sample;
  2.  
  3. public class ParsedExampleDataSet {
  4.     private String extractedString = null;
  5.     private String extractedAttr = null;
  6.     private int extractedInt = 0;
  7.  
  8.     public String getExtractedString() {
  9.          return extractedString;
  10.     }
  11.     public void setExtractedString(String extractedString) {
  12.          this.extractedString = extractedString;
  13.     }
  14.    
  15.     public void setExtractedAttr(String extractedString) {
  16.         this.extractedAttr = extractedString;
  17.    }
  18.  
  19.     public int getExtractedInt() {
  20.          return extractedInt;
  21.     }
  22.     public void setExtractedInt(int extractedInt) {
  23.          this.extractedInt = extractedInt;
  24.     }
  25.      
  26.     public String toString(){
  27.          return "ExtractedString = " + this.extractedString.trim()
  28.                    + "ExtractedAttr = " + this.extractedAttr.trim()
  29.                    + "nExtractedInt = " + this.extractedInt;
  30.     }
  31. }
  32.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.sample;
  3.  
  4. import android.app.Activity;
  5. import android.os.Bundle;
  6. import java.net.URL;
  7.  
  8. import javax.xml.parsers.SAXParser;
  9. import javax.xml.parsers.SAXParserFactory;
  10.  
  11. import org.xml.sax.InputSource;
  12. import org.xml.sax.XMLReader;
  13.  
  14. import android.util.Log;
  15. import android.widget.TextView;
  16.  
  17. public class ParsingXML extends Activity {
  18.      
  19.      private final String MY_DEBUG_TAG = "WeatherForcaster";
  20.  
  21.      /** Called when the activity is first created. */
  22.      @Override
  23.      public void onCreate(Bundle icicle) {
  24.           super.onCreate(icicle);
  25.  
  26.           /* Create a new TextView to display the parsingresult later. */
  27.           TextView tv = new TextView(this);
  28.           try {
  29.                /* Create a URL we want to load some xml-data from. */
  30.                URL url = new URL("http://www.anddev.org/images/tut/basic/parsingxml/example.xml");
  31.                //URL url = new URL("G:/Project Rough Copies/XML/program.xml");
  32.                /* Get a SAXParser from the SAXPArserFactory. */
  33.                SAXParserFactory spf = SAXParserFactory.newInstance();
  34.                SAXParser sp = spf.newSAXParser();
  35.  
  36.                /* Get the XMLReader of the SAXParser we created. */
  37.                XMLReader xr = sp.getXMLReader();
  38.                /* Create a new ContentHandler and apply it to the XML-Reader*/
  39.                ExampleHandler myExampleHandler = new ExampleHandler();
  40.                xr.setContentHandler(myExampleHandler);
  41.                
  42.                /* Parse the xml-data from our URL. */
  43.                xr.parse(new InputSource(url.openStream()));
  44.                /* Parsing has finished. */
  45.  
  46.                /* Our ExampleHandler now provides the parsed data to us. */
  47.                ParsedExampleDataSet parsedExampleDataSet =
  48.                                              myExampleHandler.getParsedData();
  49.  
  50.                /* Set the result to be displayed in our GUI. */
  51.                tv.setText("Rams"+parsedExampleDataSet.toString());
  52.                
  53.           } catch (Exception e) {
  54.                /* Display any Error to the GUI. */
  55.                tv.setText("Error: " + e.getMessage()+"Parsingxml");
  56.                Log.e(MY_DEBUG_TAG, "WeatherQueryError", e);
  57.           }
  58.           /* Display the TextView. */
  59.           this.setContentView(tv);
  60.      }
  61. }
  62.  
  63.  
Parsed in 0.045 seconds, using GeSHi 1.0.8.4


Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.sample"
      android:versionCode="1"
      android:versionName="1.0.0">
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
   
        <activity android:name=".ParsingXML"
                  android:label="@string/app_name">
            <intent-filter>
           
                <action android:name="android.intent.action.MAIN" />       
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
arams
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Fri May 08, 2009 7:45 am

Postby desuvinodkumar » Tue Jul 14, 2009 11:30 am

HI
How can i parse the xml file in the Sd card or local file.....
can u help me regarding this...
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

Postby crashraider » Tue Jul 21, 2009 6:54 pm

hi, i have a problem with spanish characters....

I need to parser a xml like:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.    <item>
  2.       <title>Madonna en Concierto</title>
  3.  
  4.       <link>http://www.zaragoza.es/ciudad/actividades/ficha_Agenda?codigo=50468</link>
  5.       <description>Lugar de Realización: Feria de Muestras de Zaragoza  Fecha: 25/07/2009-25/07/2009</description>
  6.       <pubDate>Fri, 24 Jul 2009 22:00:00 GMT</pubDate>
  7.       <guid>http://www.zaragoza.es/ciudad/actividades/ficha_Agenda?codigo=50468</guid>
  8.       <dc:date>2009-07-24T22:00:00Z</dc:date>
  9.     </item>
  10.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


The error:

Code: Select all
07-21 19:37:52.349: DEBUG/PARSER(8058): Lugar de Realizaci
07-21 19:37:52.359: WARN/System.err(8058): org.apache.harmony.xml.ExpatParser$ParseException: At line 10, column 37: not well-formed (invalid token)
07-21 19:37:52.369: WARN/System.err(8058):     at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:508)
07-21 19:37:52.389: WARN/System.err(8058):     at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
07-21 19:37:52.389: WARN/System.err(8058):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
07-21 19:37:52.389: WARN/System.err(8058):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:302)
07-21 19:37:52.389: WARN/System.err(8058):     at proyecto.noticias.noticias.onCreate(noticias.java:31)
07-21 19:37:52.389: WARN/System.err(8058):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
07-21 19:37:52.389: WARN/System.err(8058):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
07-21 19:37:52.389: WARN/System.err(8058):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
07-21 19:37:52.399: WARN/System.err(8058):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
07-21 19:37:52.399: WARN/System.err(8058):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
07-21 19:37:52.399: WARN/System.err(8058):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-21 19:37:52.409: WARN/System.err(8058):     at android.os.Looper.loop(Looper.java:123)
07-21 19:37:52.409: WARN/System.err(8058):     at android.app.ActivityThread.main(ActivityThread.java:3948)
07-21 19:37:52.409: WARN/System.err(8058):     at java.lang.reflect.Method.invokeNative(Native Method)
07-21 19:37:52.409: WARN/System.err(8058):     at java.lang.reflect.Method.invoke(Method.java:521)
07-21 19:37:52.409: WARN/System.err(8058):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
07-21 19:37:52.419: WARN/System.err(8058):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
07-21 19:37:52.419: WARN/System.err(8058):     at dalvik.system.NativeStart.main(Native Method)



But when it read Description tag, it shows me error, error with ó of "Realización". Someone knows how can i fix this?? Thanksss
crashraider
Freshman
Freshman
 
Posts: 2
Joined: Tue Jul 21, 2009 6:51 pm

Postby elendryl » Thu Jul 30, 2009 9:53 am

Hi everybody

I've tried to do the same as this tutorial (thanks to you) but i' have nothing than a "null" answer when i try to get the ID in my xml

can you give me some help ?

my xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <xml>
  2.  
  3.         <Personne>
  4.  
  5.                 <Id>00022646</Id>
  6.  
  7.                 <DisplayName>bob, dylan</DisplayName>
  8.  
  9.                 <Email>bob@dylan.fr</Email>
  10.  
  11.                 <FixedLineNumber>01164651</FixedLineNumber>
  12.  
  13.                 <FixedLineShortNumber>154</FixedLineShortNumber>
  14.  
  15.                 <MobilePhoneNumber>651654165</MobilePhoneNumber>
  16.  
  17.                 <TelephoneAstreinte></TelephoneAstreinte>
  18.  
  19.                 <TelephoneEtranger></TelephoneEtranger>
  20.  
  21.                 <SiteName>Paris</SiteName>
  22.  
  23.                 <BuildingName>C</BuildingName>
  24.  
  25.         </Personne>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


my code

handler
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.thomas.annuaire;
  2.  
  3.  
  4.  
  5. import java.util.jar.Attributes;
  6.  
  7.  
  8.  
  9. import org.xml.sax.SAXException;
  10.  
  11. import org.xml.sax.helpers.DefaultHandler;
  12.  
  13.  
  14.  
  15. public class Handler extends DefaultHandler{
  16.  
  17.         // ===========================================================
  18.  
  19.     // Fields
  20.  
  21.     // ===========================================================
  22.  
  23.    
  24.  
  25.     private boolean in_outertag = false;
  26.  
  27.     private boolean in_innertag = false;
  28.  
  29.     private boolean in_id = false;
  30.  
  31.     private boolean in_displayname = false;
  32.  
  33.     private boolean in_email = false;
  34.  
  35.     private boolean in_fixedlinenumber= false;
  36.  
  37.     private boolean in_fixedlineshortnumber=false;
  38.  
  39.     private boolean in_mobilephonenumber=false;
  40.  
  41.     private boolean in_telephoneastreinte=false;
  42.  
  43.     private boolean in_telephoneetranger=false;
  44.  
  45.     private boolean in_sitename=false;
  46.  
  47.     private boolean in_buildingname=false;
  48.  
  49.    
  50.  
  51.     private ParsedDataSet myParsedDataSet = new ParsedDataSet();
  52.  
  53.  
  54.  
  55.     // ===========================================================
  56.  
  57.     // Getter & Setter
  58.  
  59.     // ===========================================================
  60.  
  61.  
  62.  
  63.     public ParsedDataSet getParsedData() {
  64.  
  65.          return this.myParsedDataSet;
  66.  
  67.     }
  68.  
  69.  
  70.  
  71.     // ===========================================================
  72.  
  73.     // Methods
  74.  
  75.     // ===========================================================
  76.  
  77.  
  78.  
  79.     public void startDocument() throws SAXException {
  80.  
  81.          this.myParsedDataSet = new ParsedDataSet();
  82.  
  83.     }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.     public void endDocument() throws SAXException {
  90.  
  91.          // Nothing to do
  92.  
  93.     }
  94.  
  95.  
  96.  
  97.     /** Gets be called on opening tags like:
  98.  
  99.      * <tag>
  100.  
  101.      * Can provide attribute(s), when xml was like:
  102.  
  103.      * <tag attribute="attributeValue">*/
  104.  
  105.  
  106.  
  107.     public void startElement(String namespaceURI, String localName,
  108.  
  109.               String qName, Attributes atts) throws SAXException {
  110.  
  111.          if (localName.equals("xml")) {
  112.  
  113.               this.in_outertag = true;
  114.  
  115.          }else if (localName.equals("Personne")) {
  116.  
  117.               this.in_innertag = true;
  118.  
  119.          }else if (localName.equals("Id")) {
  120.  
  121.               this.in_id = true;
  122.  
  123.          }else if (localName.equals("DisplayName"))  {
  124.  
  125.            this.in_displayname= true;
  126.  
  127.          }else if (localName.equals("Email"))  {
  128.  
  129.              this.in_email= true;
  130.  
  131.          }else if (localName.equals("FixedLineNumber"))  {
  132.  
  133.              this.in_fixedlinenumber= true;
  134.  
  135.          }else if (localName.equals("FixedLineShortNumber"))  {
  136.  
  137.              this.in_fixedlineshortnumber= true;
  138.  
  139.          }else if (localName.equals("MobilePhoneNumber"))  {
  140.  
  141.              this.in_mobilephonenumber= true;
  142.  
  143.          }else if (localName.equals("TelephoneAstreinte"))  {
  144.  
  145.              this.in_telephoneastreinte= true;
  146.  
  147.          }else if (localName.equals("TelephoneEtranger"))  {
  148.  
  149.              this.in_telephoneetranger= true;
  150.  
  151.          }else if (localName.equals("SiteName"))  {
  152.  
  153.              this.in_sitename= true;
  154.  
  155.          }else if (localName.equals("BuildingName"))  {
  156.  
  157.              this.in_buildingname= true;    
  158.  
  159.        }  
  160.  
  161.          }
  162.  
  163.              
  164.  
  165.    
  166.  
  167.     /** Gets be called on closing tags like:
  168.  
  169.      * </tag> */
  170.  
  171.  
  172.  
  173.     public void endElement(String namespaceURI, String localName, String qName)
  174.  
  175.               throws SAXException {
  176.  
  177.         if (localName.equals("xml")) {
  178.  
  179.             this.in_outertag = false;
  180.  
  181.        }else if (localName.equals("Personne")) {
  182.  
  183.             this.in_innertag = false;
  184.  
  185.        }else if (localName.equals("Id")) {
  186.  
  187.             this.in_id = false;
  188.  
  189.        }else if (localName.equals("DisplayName"))  {
  190.  
  191.          this.in_displayname= false;
  192.  
  193.        }else if (localName.equals("Email"))  {
  194.  
  195.            this.in_email= false;
  196.  
  197.        }else if (localName.equals("FixedLineNumber"))  {
  198.  
  199.            this.in_fixedlinenumber= false;
  200.  
  201.        }else if (localName.equals("FixedLineShortNumber"))  {
  202.  
  203.            this.in_fixedlineshortnumber= false;
  204.  
  205.        }else if (localName.equals("MobilePhoneNumber"))  {
  206.  
  207.            this.in_mobilephonenumber= false;
  208.  
  209.        }else if (localName.equals("TelephoneAstreinte"))  {
  210.  
  211.            this.in_telephoneastreinte= false;
  212.  
  213.        }else if (localName.equals("TelephoneEtranger"))  {
  214.  
  215.            this.in_telephoneetranger= false;
  216.  
  217.        }else if (localName.equals("SiteName"))  {
  218.  
  219.            this.in_sitename= false;
  220.  
  221.        }else if (localName.equals("BuildingName"))  {
  222.  
  223.            this.in_buildingname= false;    
  224.  
  225.      }  
  226.  
  227.     }
  228.  
  229.     public void characters(char ch[], int start, int length) {
  230.  
  231.         if(this.in_id){
  232.  
  233.         myParsedDataSet.setId(new String(ch, start, length));
  234.  
  235.         }
  236.  
  237. }
Parsed in 0.058 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.thomas.annuaire;
  2.  
  3.  
  4.  
  5. public class ParsedDataSet {
  6.  
  7.        
  8.  
  9.         private String Id = null;
  10.  
  11.     private String DisplayName=null;
  12.  
  13.     private String FixedLineNumber=null;
  14.  
  15.     private String FixedLineShortNumber=null;
  16.  
  17.     private String MobilePhoneNumber=null;
  18.  
  19.     private String TelephoneAstreinte=null;
  20.  
  21.     private String TelephoneEtranger=null;
  22.  
  23.     private String SiteName=null;
  24.  
  25.     private String BuildingName=null;
  26.  
  27.    
  28.  
  29.    
  30.  
  31.  
  32.  
  33.     public String getId() {
  34.  
  35.          return Id;
  36.  
  37.     }
  38.  
  39.     public void setId(String Id) {
  40.  
  41.          this.Id = Id;
  42.  
  43.     }
  44.  
  45.  
  46.  
  47.      
  48.  
  49.    // exemple recupération info
  50.  
  51.     public String toString(){
  52.  
  53.          return "id = " + this.Id;
  54.  
  55.                    
  56.  
  57.     }
  58.  
  59.    
  60.  
  61. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4
Last edited by elendryl on Thu Jul 30, 2009 10:38 am, edited 1 time in total.
elendryl
Freshman
Freshman
 
Posts: 9
Joined: Thu Jul 30, 2009 9:43 am

Postby padde » Thu Jul 30, 2009 10:29 am

Well... all you do in your code is setting the tags true and false.. but you never read whats between start and end tag.
Maybe you should read attentively the examples in this thread anew.

Hint: public void characters(...) is what you need
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests