parsing xml data

by jj » Fri, 13 Mar 2009 17:25:46 GMT


Sponsored Links
 Hi everyone

I am trying to parse some data (wrapped in a String), that has xml
format
following is the code that I am using, with no much succes so far :(



    private void parseXml(String str)
    {
        XMLReader myReader=null;

        System.setProperty
("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver");


         try
         {
           myReader = XMLReaderFactory.createXMLReader();
         }
         catch (SAXException e)
         {
                 Log.i("activity","error  = "+e.toString());
         }


        try
        {
                myReader.parse(str);
        }
        catch (IOException e)
        {
                Log.i("activity","error  = "+e.toString());
        }
        catch (SAXException e)
        {
                Log.i("activity","error  = "+e.toString());
                //it fails here!!!
        }

}

when I do myReader.parse(str), I get the following error:
java.io.FileNotFoundException
I guess is because it's trying to acces a file, but what I am trying
to parse is just some data that I have in the String variable, not a
file...

can anybody tell me what I am doing wrong?


Thanks a lot



--~--~---------~--~----~------------~-------~--~----~



parsing xml data

by petunio » Fri, 13 Mar 2009 17:27:11 GMT


 Hi everyone

I am trying to parse some data (wrapped in a String), that has xml
format
following is the code that I am using, with no much succes so far :(

    private void parseXml(String str)
    {
        XMLReader myReader=null;

        System.setProperty
("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver");

         try
         {
           myReader = XMLReaderFactory.createXMLReader();
         }
         catch (SAXException e)
         {
                 Log.i("activity","error  = "+e.toString());
         }

        try
        {
                myReader.parse(str);
        }
        catch (IOException e)
        {
                Log.i("activity","error  = "+e.toString());
        }
        catch (SAXException e)
        {
                Log.i("activity","error  = "+e.toString());
                //it fails here!!!
        }

}

when I do myReader.parse(str), I get the following error:
java.io.FileNotFoundException
I guess is because it's trying to acces a file, but what I am trying
to parse is just some data that I have in the String variable, not a
file...

can anybody tell me what I am doing wrong?

Thanks a lot
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


parsing xml data

by Pd » Fri, 13 Mar 2009 18:25:12 GMT


 You need either InputSource or URI.

 http://www.saxproject.org/apidoc/org/xml/sax/XMLReader.html 





--~--~---------~--~----~------------~-------~--~----~



parsing xml data

by mafro » Fri, 13 Mar 2009 18:27:47 GMT


 >From the docs:


So the parse() method doesn't accept XML as a String input - it
accepts a path to a file. This is what causes your exception.

Where does your XML come from originally? The SAX parser is designed
to parse directly from a Stream, so wherever your XML is first loaded,
parse it there.

mafro




--~--~---------~--~----~------------~-------~--~----~



parsing xml data

by mafro » Fri, 13 Mar 2009 22:16:00 GMT


 Please don't post in two forums at the same time.. jeez




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to test new apps?

Hi All,

If there is a new application deployed on Android SDK, what is the
best way to test it? ( Junit or android.test )

And can Python be used to test apps?

Thanks,
-Marcus

--~--~---------~--~----~------------~-------~--~----~

2. Music Streaming

Hey,

I was wondering if anyone knows of an android app that streams music
(mp3s) from your pc to your (g1 mobile) using either the G3 internet
connection or the WI-FI connection?

Thanks!
Daz

--~--~---------~--~----~------------~-------~--~----~

3. long click

4. log on to web page

5. Read/write files on the device SD card from a desktop/laptop application

6. Problem with the onUpdate method of an SQLiteOpenHelper

7. Read/write files on the device SD card from a desktop/laptop application