• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

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

0
rajivbal_98
Asked:
rajivbal_98
  • 3
  • 3
1 Solution
 
CEHJCommented:
Why not just do this at source?
0
 
TimYatesCommented:
<xml><![CDATA[ <= ]]></xml>
0
 
CEHJCommented:
That's another way of doing it at source ;-)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
TimYatesCommented:
Heh, true ;-)
0
 
grim_toasterCommented:
So let me get this right, what you want to do is basically treat it as a string, and replace all instances of one character with another, if so then the below should work (although this is NOT production quality code).

    private static final char[] from = { '&', '<', '>' };
    private static final String[] to = { "&amp;", "&lt;", "&gt;" };
   
     public static void main(String[] arguments) throws Exception
     {
             String sampleString = "This is some sample text & heres some more <>";
             
             for (int i = 0, n = from.length; i < n; i++)
                 sampleString = replace(sampleString, from[i], to[i]);
             
             System.err.println("!!!!sampleString = " + sampleString);
     }
     
     private static String replace(String in, char from, String to)
     {
          return in;
     }


Actually, changed my mind, I'll leave the implementation of the replace method up to you!  That's the fun part after all!  And it would be preferable to do it at source.  But there's a starting point for you anyway! :-P
0
 
CEHJCommented:
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("\""));
  }
}
0
 
TimYatesCommented:
I remember when it was just

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

*sigh*
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now