Link to home
Start Free TrialLog in
Avatar of rajivbal_98
rajivbal_98

asked on

Problems with Oracle Parser

Hi

I am using Oracle Parser xmlparserv2.jar

I am generating xml files and reading files through Oracle Parser

Well Sometimes i get value <= or >=

for example <xml> <= </xml>
This Gives error while parsing in Oracle parser

Well wht i have done replaced < with &gt and > with &lt . But i have generic bean which does all this stuff. Its not possible for to change everywhere . So can someone give me a function where in it should replace < to &lt and > to &gt ..

So any other solution you have it , it would be appreciated .

Plz give the answer as soon as possible .

Thkx

Regards

Rajiv

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Why not just do this at source?
<xml><![CDATA[ <= ]]></xml>
That's another way of doing it at source ;-)
Heh, true ;-)
ASKER CERTIFIED SOLUTION
Avatar of grim_toaster
grim_toaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want one of those - here's one:

public class HTMLEscape
{
  public static String escape( String s )
  {
    int len = s.length();
    StringBuffer sb = new StringBuffer(len*5/4);

    for ( int i = 0; i < len; i++ )
    {
      char c = s.charAt( i );
      String elem = htmlchars[c&0xff];

      sb.append( elem == null ? ""+c : elem );
     }
     return sb.toString();
  }

  private static String htmlchars[] = new String[256];

  static
  {
    String entry[] = {
      "nbsp", "iexcl", "cent", "pound", "curren", "yen", "brvbar",
      "sect", "uml", "copy", "ordf", "laquo", "not", "shy", "reg",
      "macr", "deg", "plusmn", "sup2", "sup3", "acute", "micro",
      "para", "middot", "cedil", "sup1", "ordm", "raquo", "frac14",
      "frac12", "frac34", "iquest",
      "Agrave", "Aacute", "Acirc", "Atilde", "Auml", "Aring", "AElig",
      "CCedil", "Egrave", "Eacute", "Ecirc", "Euml", "Igrave", "Iacute",
      "Icirc", "Iuml", "ETH", "Ntilde", "Ograve", "Oacute", "Ocirc",
      "Otilde", "Ouml","times", "Oslash", "Ugrave", "Uacute", "Ucirc",
      "Uuml", "Yacute", "THORN", "szlig",
      "agrave", "aacute", "acirc", "atilde", "auml", "aring", "aelig",
      "ccedil", "egrave", "eacute", "ecirc", "euml", "igrave", "iacute",
      "icirc", "iuml", "eth", "ntilde", "ograve", "oacute", "ocirc",
      "otilde", "ouml", "divid", "oslash", "ugrave", "uacute", "ucirc",
      "uuml", "yacute", "thorn", "yuml"
    };

    htmlchars['&'] = "&amp;";
    htmlchars['<'] = "&lt;";
    htmlchars['>'] = "&gt;";

    for ( int c = '\u00A0', i=0 ; c <= '\u00FF'; c++, i++ )
      htmlchars[c] = "&"+entry[i]+";";

    for ( int c = '\u0083', i=131 ; c <= '\u009f'; c++, i++ )
      htmlchars[c] = "&#"+i+";";

    htmlchars['\u0088']=htmlchars['\u008D']=htmlchars['\u008E'] = null;
    htmlchars['\u008F']=htmlchars['\u0090']=htmlchars['\u0098'] = null;
    htmlchars['\u009D'] = null;
  }

  // For testing
  public static void main( String args[] )
  {
    System.out.println(HTMLEscape.escape("\""));
  }
}
I remember when it was just

&copy; &lt; &gt; and &reg;

*sigh*