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. Add libdl to accRuntimeTest link command

I am trying to build Android 2.1 on Fedora 13, and the build is
failing because the linker can't find dlsym when
it tries to link accRuntimeTest.  dlsym is in libdl, and whatever
jiggery-pokery enabled the linker to auto-
magically find it in previous Fedora releases is no longer there.

What do I need to do to the makefiles to get libdl (-ldl) added to the
linker command for accRuntimeTest?

Thanks!

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. Changing Main/Launch activity

I think I already know the answer to this, but I just wanted to
confirm (I think no horrible ramifications):

Are there any ramifications to changing the "MAIN"/"LAUNCHER" tags in
the manifest to a different activity?  See example below:

(original manifest segment)
-----------------------
<activity android:name=".MyAppMain"
   android:label="@string/app_name" android:theme="@android:style/
Theme.NoTitleBar">
          <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
</activity>
<activity android:name=".MySecondActivity"
  android:label="@string/numbertwo"
  android:theme="@android:style/Theme.NoTitleBar">
</activity>
------------------------


(new manifest segment)
------------------------
<activity android:name=".MyAppMain"
   android:label="@string/app_name" android:theme="@android:style/
Theme.NoTitleBar">
</activity>
<activity android:name=".MySecondActivity"
  android:label="@string/numbertwo"
  android:theme="@android:style/Theme.NoTitleBar">
          <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
</activity>
------------------------

Thanks,

Justin

-- 

3. Can i remove my status bar notification without opening my app?

4. How to compile and install mplayer from source code

5. how to check if the current thread is in the ui thread?

6. Glitch in Eclipse SDK - Can't select Build Target

7. Newbie befuddlement -- wrong text in "HelloWorld" type app