Solved

Problems with Oracle Parser

Posted on 2003-12-03
7
426 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
Comment Utility
Why not just do this at source?
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
<xml><![CDATA[ <= ]]></xml>
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
That's another way of doing it at source ;-)
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 35

Expert Comment

by:TimYates
Comment Utility
Heh, true ;-)
0
 
LVL 7

Accepted Solution

by:
grim_toaster earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
I remember when it was just

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

*sigh*
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now