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. test automation for mobile phone testing?

I am working on mobile application testing. Is there a tool that we
can use to automate tests on Android platform. Sorry if this has been
asked earlier, i am new to this group. :)

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

2. Is there a way to change the website entered on registration

Hello all I have not yet finished my registration pending this
question is the website entered on developer registration important?
And if so is it changeable upon completing the sign up? I cannot seem
to go back and change it during my registration as google seems to
have made the process rather one directional even after login out and
back in.

Thanks in advance,
Pete

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

3. Anatomy of receiving a call

4. Add open Wifi to preffered list.

5. "invalid statement in fillwindow"

6. bug? InputMethodManager.isWatchingCursor()

7. imeem and buffering audio with MediaPlayer