Solved

Problems with Oracle Parser

Posted on 2003-12-03
7
430 Views
Last Modified: 2007-12-19
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
Comment
Question by:rajivbal_98
  • 3
  • 3
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9866995
Why not just do this at source?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9867141
<xml><![CDATA[ <= ]]></xml>
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9867204
That's another way of doing it at source ;-)
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 35

Expert Comment

by:TimYates
ID: 9867218
Heh, true ;-)
0
 
LVL 7

Accepted Solution

by:
grim_toaster earned 125 total points
ID: 9867644
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9867668
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
 
LVL 35

Expert Comment

by:TimYates
ID: 9867707
I remember when it was just

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

*sigh*
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 72
eclipse argument 14 60
even odd program using while loop 3 40
How do I remove an object from a 3 23
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question