Just in case you want to escape/unescape them (it's a little better), here
is what I use (they are C#, but easy to convert to Java). They are simple. I
found the original on the web, but don't remember the author to give the
credit to :


    public String EscapeXML(String str)
    {
        StringBuilder sb = new StringBuilder();
        foreach (Char c in str)
        {
            switch (c)
            {
                case '&':
                    sb.Append("&");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
            }
        }
        return sb.ToString();
    }

This one could be made faster, but it's simple :).

    public String Unescape(String str)
    {
        str = str.Replace("&amp;", "&");
        str = str.Replace("&lt;", "<");
        str = str.Replace("&gt;", ">");
        str = str.Replace("&#039;", "\\");
        str = str.Replace("&#39;", "'");
        str = str.Replace("&quot;", "\"");
        str = str.Replace("&lt;", "<");
        return str;
    }



Sincerely,
 
Brad Gies
 
 
-----------------------------------------------------------------
Brad Gies
27415 Greenfield Rd, # 2,
Southfield, MI, USA
48076
www.bgies.com  www.truckerphone.com 
www.EDI-Easy.com  www.pricebunny.com
-----------------------------------------------------------------
 
Moderation in everything, including abstinence

-----Original Message-----
From: android-developers@googlegroups.com
[mailto:android-develop...@googlegroups.com] On Behalf Of 3D
Sent: Thursday, January 29, 2009 3:59 PM
To: Android Developers
Subject: [android-developers] Re: SAXParser getting stuck on certain
characters


Thank you both for your responses!  I think I will try just removing
these characters.

On Jan 28, 9:14 am, "Brad Gies" <rbg...@gmail.com> wrote:
> Well.  the best thing to do would be to escape those characters at the
> server that sends the document, but if that is not possible then you could
> download the document into a Stream, escape them there, or even remove
them,
> and then pass it to the SAX parser. Later, if you display the contents,
you
> would have to unescape the contents before you display it.
>
> Sincerely,
>
> Brad Gies
>
> -----------------------------------------------------------------
>
> Brad Gies
>
> 27415 Greenfield Rd, # 2,
>
> Southfield, MI, USA
>
> 48076
>
> www.bgies.com www.truckerphone.com
>
> www.EDI-Easy.com www.pricebunny.com
>
> -----------------------------------------------------------------
>
> Moderation in everything, including abstinence
>
>   _____  
>
> From: android-developers@googlegroups.com
> [mailto:android-develop...@googlegroups.com] On Behalf Of Tim Bray
> Sent: Tuesday, January 27, 2009 3:21 PM
> To: android-developers@googlegroups.com
> Subject: [android-developers] Re: SAXParser getting stuck on certain
> characters
>
> On Tue, Jan 27, 2009 at 12:10 PM, 3D <ernestgfre...@gmail.com> wrote:
>
> I'm using a SAXParser to parse an XML document and its getting stuck
> on certain symbols like the 'trademark' symbol and I think even double-
> quotes ".  I really don't need these characters so it would be fine if
> the parser just skips over these.  Instead it throws an exception and
> quits parsing the document.  What can I do?
>
> XML is very fussy about character encoding. If your supposedly XML doc has
> malformed characters (for example, if some UTF-8 got dropped into what you
> think was ASCII, or ISO-8859 into UTF-8), well, it's not XML, sorry, and
the
> software won't let you do that.  This is controversial (many people have
> historically thought it's OK to ignore internationalization problems) but
> it's the way it is, you're stuck with it.  
>
> There are other parsers like TagSoup and one in xmllib2 that will let you
> bypass breakage and go on working, but they're pretty big chunks of code.
> -Tim


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to