harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject Re: SAXParseException: Illegal: ]]>
Date Wed, 22 Apr 2009 15:00:12 GMT
Mariano,

You may well be on the wrong list...

I have run your test case on the latest Harmony code, and it seems to
complete ok,

  C:\harmony-jdk-761593\jre\bin>java -showversion -cp \temp\test.jar Test
  Apache Harmony Launcher : (c) Copyright 1991, 2008 The Apache Software
Foundation or its licensors, as applicable.
  java version "1.5.0"
  pre-alpha : not complete or compatible
  svn = r761593, (Apr  3 2009), Windows/ia32/msvc 1310, release build
  http://harmony.apache.org
  OK? => true

I believe that Android uses a different XML parser to Harmony.
We use the Apache parser (http://xml.apache.org) and I believe Android
uses a different parser.

You might want to ask your question again on the Android developers'
list (http://groups.google.com/group/android-developers).

Regards,
Tim


Mariano Kamp wrote:
> Hi,
> 
>   please, if I am on the wrong list here, could you just point me to
> the right place?
> 
>   Ok,I have a smaller test case now:
> 
> DocumentBuilder builder =
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
> String in = "<category term=\"&lt;![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 with Harmony. 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.StringReader@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=\"&lt;![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=\"&lt;![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 1:52 PM, Mariano Kamp <mariano.kamp@gmail.com> wrote:
>> Hi,
>>
>>  I am not sure if this is the right list, but I thought I start out
>> where the stack trace points me ;-)
>>
>>  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.BufferedReader@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="&lt;![CDATA[ Agenda ]]&gt;"/>
>>
>>  Any idea why this happens?
>>
>>  This is the (abbreviated) code I use to parse the stream from Google.
>>
>> 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));
>>
>>  ???
>>
>>  Maybe Google doesn't generate proper XML? I don't know. I originally
>> converted my code back to use DOM like above, because I got the same
>> problem with kXML, but they state in their documentation that it
>> doesn't support this escaping, I think:
>>
>>  n order to keep kXML as small as possible, no efforts are made to recognize
>> certain well-formedness errors that would require additional detection code,
>> such as
>>   - ']]>' contained in text content,
>>   - duplicate attributes, and
>>   - <? folowed by a space before the targe
>>
>>
>> Cheers,
>> Mariano
>>
> 

Mime
View raw message