Ok,
I have a smaller test case now:
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
String in = "<category term=\"<![CDATA[ Work in
progress
]]>\"><test/></category>";
Document d = builder.parse(new InputSource(new
StringReader(in)));
System.out.println("OK? => "
+
(d.getDocumentElement().getElementsByTagName("test").getLength() == 1));
It works with the Standard SDK, but not on Android. The full code is
below this post.
Standard SDK:
mariano-kamps-macbook-pro:~ mkamp$
/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java
-version
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)
Result: OK? => true
With Android:
W/System.err( 5135): org.xml.sax.SAXParseException: Illegal: ]]>
(position:START_TAG <category term='null'>@1:49 in
java.io.stringrea...@433eee78)
W/System.err( 5135): at
org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:151)
W/System.err( 5135): at test.xml.TestActivity.onCreate(TestActivity.java:23)
W/System.err( 5135): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122)
W/System.err( 5135): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2103)
W/System.err( 5135): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2156)
W/System.err( 5135): at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
W/System.err( 5135): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
W/System.err( 5135): at android.os.Handler.dispatchMessage(Handler.java:88)
W/System.err( 5135): at android.os.Looper.loop(Looper.java:123)
W/System.err( 5135): at
android.app.ActivityThread.main(ActivityThread.java:3742)
W/System.err( 5135): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 5135): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err( 5135): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
W/System.err( 5135): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
W/System.err( 5135): at dalvik.system.NativeStart.main(Native Method)
I/ActivityManager( 58): Displayed activity test.xml/.TestActivity: 537 ms
Cheers,
Mariano
Full code goes here.
Standard SDK:
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class Test {
public static void main(String[] args) throws Exception {
try {
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
String in = "<category term=\"<![CDATA[ Work in
progress
]]>\"><test/></category>";
Document d = builder.parse(new InputSource(new
StringReader(in)));
System.out.println("OK? => "
+
(d.getDocumentElement().getElementsByTagName("test").getLength() == 1));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Android:
package test.xml;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import android.app.Activity;
import android.os.Bundle;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
String in = "<category term=\"<![CDATA[ Work in
progress
]]>\"><test/></category>";
Document d = builder.parse(new InputSource(new
StringReader(in)));
System.out.println("OK? => "
+
(d.getDocumentElement().getElementsByTagName("test").getLength() == 1));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
On Wed, Apr 22, 2009 at 3:55 PM, Mariano Kamp <[email protected]> wrote:
> Hey,
>
> thanks for showing an interest!
>
> No, it's not the whole XML and I should have mentioned that.
>
> I'll send you the complete file (92k) by mail. But the offending part
> is in here.
>
> Cheers,
> Mariano
>
> On Wed, Apr 22, 2009 at 3:51 PM, Streets Of Boston
> <[email protected]> wrote:
>>
>> If your example is the entire XML you try to parse, then the exception
>> is valid.
>> Here is the snippet i tried:
>>
>> <category term="user/xyz/state/com.google/reading-list" scheme="http://
>> www.google.com/reader/" label="reading-list"/>
>> <category term="user/xyz/state/com.google/fresh" scheme="http://
>> www.google.com/reader/" label="fresh"/>
>> <category term="<![CDATA[ Agenda ]]>"/>
>>
>> taken from your post.
>>
>> Your example is not a valid XML document: It is missing a root-
>> element.
>> This would be valid:
>>
>> <some_root_elm>
>> <category term="user/xyz/state/com.google/reading-list"
>> scheme="http://www.google.com/reader/" label="reading-list"/>
>> <category term="user/xyz/state/com.google/fresh" scheme="http://
>> www.google.com/reader/" label="fresh"/>
>> <category term="<![CDATA[ Agenda ]]>"/>
>> </some_root_elm>
>>
>>
>> When I tried to paste your example in an XML editor, i got a similar
>> error that you got in your DOM parser. The fact that ']]>' is
>> mentioned may be because it is the last thing parsed in your XML
>> snippet.
>>
>> Try to put a root-element as the parent of your three category
>> elements and see if you still get the problem.
>>
>> On Apr 22, 8:08 am, Mariano Kamp <[email protected]> wrote:
>>> Hi,
>>>
>>> yesterday I bitched about all the issues I have with the kXML
>>> parser.
>>> (http://groups.google.com/group/android-developers/browse_thread/threa...)
>>>
>>> So now I converted my code to use DOM. And I tried the third example
>>> from my referenced mail and it gives me an exception too.
>>>
>>> I get a SAXParseExeption when parsing an atom feed from Google Reader:
>>>
>>> org.xml.sax.SAXParseException: Illegal: ]]> (position:START_TAG
>>> <category term='user/xyz/state/com.google/fresh'>@5:15061 in
>>> java.io.bufferedrea...@4348a0e8)
>>> at
>>> org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:151)
>>> at com.newsrob.U.parseXMLfromInputStream(U.java:45)
>>> at
>>> com.newsrob.EntriesRetriever.fetchNewEntries(EntriesRetriever.java:299)
>>> at
>>> com.newsrob.SynchronizationService$4.run(SynchronizationService.java:172)
>>> at
>>> com.newsrob.SynchronizationService.doSync(SynchronizationService.java:337)
>>> at
>>> com.newsrob.SynchronizationService.access$0(SynchronizationService.java:86)
>>> at
>>> com.newsrob.SynchronizationService$1.run(SynchronizationService.java:75)
>>> at java.lang.Thread.run(Thread.java:935)
>>>
>>> I think the problem originates here (see the last category tag):
>>>
>>> <category term="user/xyz/state/com.google/reading-list"
>>> scheme="http://www.google.com/reader/" label="reading-list"/><category
>>> term="user/xyz/state/com.google/fresh"
>>> scheme="http://www.google.com/reader/" label="fresh"/><category
>>> term="<![CDATA[ Agenda ]]>"/>
>>>
>>> Any idea why this happens?
>>>
>>> This is the (abbreviated) code I use to parse the stream from Google
>>> Reader.
>>>
>>> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
>>> dbf.setCoalescing(true); // added this later with no effect
>>>
>>> DocumentBuilder builder = dbf.newDocumentBuilder();
>>>
>>> BufferedReader br = new BufferedReader(new
>>> InputStreamReader(is,"UTF-8"), 8 * 1024);
>>> builder.parse(new InputSource(br));
>>>
>>> Any help is appreciated.
>>>
>>> Is there a third parser on Android, besides Harmony's SAXParser and
>>> kXML's Pull Parser?
>>>
>>> Cheers,
>>> Mariano
>> >>
>>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---