Solved

Problems with Oracle Parser

Posted on 2003-12-03
7
431 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What's wrong with this code? 4 36
String array comparison 4 46
Selenium docs api java index 3 69
batch vs regular insert in spring DAO 2 26
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

697 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