Disple html using JEditorPane

I want display html file using JEditorPane
but I become an exception
java.net.MalformedURLException: unknown protocol: e
what schould be the problem
       import javax.swing.*;
       import java.net.URL;
       import java.io.File;
public class Browser extends JFrame
      JEditorPane  ePane = new JEditorPane();
      public Browser(){
          this.setBounds(200,50,700,650);
          this.setLayout(null);
          ePane.setBounds(50,20, 600,500);
          try {
                   File file = new File("xx.html");
                   String ss = file.getAbsolutePath();
                 URL url = new URL(ss);
                 ePane.setPage(url);
             } catch (java.io.IOException ex) { ex.printStackTrace(); }
          this.add(ePane);
}  

               File file = new File("xx.html");"xx.html" lacks a protocol, like "http" or "ftp". But anyway, why not just use File.toURL()?

Similar Messages

  • Use JEditorPane to display HTML and RTF ?

    Hello,
    Is it possible to use JEditorPane to open a HTML file and then save it as RTF?
    And open a RTF file and save it as HTML ???
    Eric

    bump...
    has anyone a solution to this?
    I have a form that allows users to add raw HTML code. Now I want to display the formatted version in a report but the tags show in the report instead...any suggestions?
    regards
    Paul P

  • How to show an html page using JEditorPane in applet.

    I have never use jeditorpane with applet so i dont know how to show a html page.if you have some code or any example then please posted that.Thanks

    public class MyApplet extends JApplet{
        private JTextPane textPane = null;
        public void init(){
        HTMLEditorKit editorKit = new HTMLEditorKit();
        HTMLDocument  htmlDoc   = (HTMLDocument)editorKit.createDefaultDocument();
        textPane  = new JTextPane();
        textPane.setEditable(false);
        textPane.setEditorKit(editorKit);
        textPane.setContentType("text/html");
        textPane.setDocument(htmlDoc);
        Container c = getContentPane();
        c.add(new JScrollPane(textPane),    BorderLayout.CENTER);
        c.add(buttonPanel,                  BorderLayout.SOUTH);
        c.add(Box.createVerticalStrut(5),   BorderLayout.NORTH);     
        c.add(Box.createHorizontalStrut(5), BorderLayout.EAST);     
        c.add(Box.createHorizontalStrut(5), BorderLayout.WEST);
        public void setHtml(String html){
            // you should check the textpane's document to detrmine if there
            // is already text in there..if so, then clear the textpane text and then
            // set the new html...Note: JTextPane only show basic Html ..
            // not like a full blown browser
            textPane.setTextt(html);
            textPane.setCaretPosition(0);
    }

  • Edit html in JEDITORPANE

    HEllo friends!
    I need your help, for editing html in editorpane.
    I want to create a textarea in which the user type simple text than select some part of it & makes it bold, italic etc. by using an event of button or popup any thing.
    So guide me that which textcomponent provide this , i already used JEditorPane, and insert tags manually but it is not good, if i try to overlap the tags og italic & bold.
    So please help me is this any way pre built to provide these func. of add html tags in jeditorpane & use see the render html test in area.
    than please provide me. at [email protected]
    Thanks
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import javax .swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.IOException;
    public class TestJEditor extends JFrame {
    Panel p1 = new Panel();
    JButton b1 = new JButton("BOLD");
    JButton b2 = new JButton("ITALIC");
    BorderLayout borderLayout1 = new BorderLayout();
    JScrollPane jScrollPane1 = new JScrollPane();
    JEditorPane jEditorPane1 = new JEditorPane();
    HTMLEditorKit editorKit = new HTMLEditorKit();
    DefaultEditorKit defaultKit = new DefaultEditorKit();
    public TestJEditor() {
    super("Note");
    this.getContentPane().add(p1);
    //jEditorPane1.setEditable(false);
    jEditorPane1.setEditorKit(editorKit);
    p1.setLayout(null);
    p1.add(jScrollPane1);
    jScrollPane1.setBounds(10, 10, 350, 100);
    jScrollPane1.getViewport().add(jEditorPane1, null);
    b1.setBounds(370, 10, 100, 20);
    p1.add(b1);
    b2.setBounds(370, 40, 100, 20);
    p1.add(b2);
    b1.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e)
         // jEditorPane1.setEditorKit(defaultKit);
         String str = jEditorPane1.getText();
         System.out.println(str);
         String temp = jEditorPane1.getSelectedText();
         if(temp.indexOf("<B>") != 0)
         int start = str.indexOf(temp);
         int end = start + temp.length();
         System.out.println("start "+start+" end "+end);
         str = str.substring(0,start)+"<B>"+str.substring(start,end)+"</B>"+str.substring(end);
         jEditorPane1.setText(str);
         //System.out.println(jEditorPane1.getText());
    b2.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e)
         String str = jEditorPane1.getText();
         System.out.println(str);
         String temp = jEditorPane1.getSelectedText();
         System.out.println("Italic");
         int start = str.indexOf(temp);
         int end = start + temp.length();
         str = str.substring(0,start)+"<I>"+str.substring(start,end)+"</I>"+str.substring(end);
         jEditorPane1.setText(str);
    public static void main(String[] args) {
    JFrame frame = new TestJEditor();
    frame.setSize(600,500);
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    //frame.pack();
    frame.show();
    }

    Hi kashif10,
    JEditorPane or JTextPane are the classes to use. You can have both bold and italic for a text portion.
    See http://java.sun.com/products/jfc/tsc/articles/ for an overview of articles covering the swing text package.
    Or try application SimplyHTML at http://www.lightdev.com/template.php4?id=3 it is open source and has a lot of documentation too.
    Ulrich

  • Display HTML in JEditorPane

    Hi
    I am trying to display a String containing HTML text on a JEditorPane.
    I have downloaded the HTML from a webpage using sockets, and now I want to display the downloaded page. I have a project in school about sockets.
    This is why I can't use getPage(URL);
    The following is the code I am using:
    String temp = "String with HTML text"
    HTMLEditorKit htmlEdKit = new HTMLEditorKit();
    JEditorPane.setEditorKit(htmlEdKit);
    JEditorPane.setContentType("text/html");
    JEditorPane.setEditorKitForContentType("text/html", htmlEdKit);
    JEditorPane.setContentType("text");
    JEditorPane.setText(temp);
    When I run the code, all that is displaying is the raw HTML code, with all the tags. As I understand it, this is how it should be done.
    What is wrong, would appreciate some help.
    /David Mossberg

    it's not necessary to use socket but if use socket get the inputstream from it.
    in = socket.getinputstream(); //return inputstream from socket
    htmldoc = JEditorPane.getDocument(); //return the htmldoc in JEditorPane
    if(htmldoc.getlength()>0)
    htmldoc.remove(0,htmlDoc.getLength());//if the htmldoc has some content then remove it
    reader = new InputStreamReader(in);//construct a new reader from in
    JEditorPane.getEditorKit.read(reader,htmldoc,0); //read new content into the htmldoc from reader
    Hope the above code helps you.
    joney

  • Facing problem in using JEditorPane as renderer for JList

    I am trying to use JEditorPane as renderer for a list. But I am facing some problems. First problem is the output in the editorpane is not shown properly. I want to show a html file, but only portion of the first line that is viewable in the editorpane is shown. I, of course, need to show the total content of the file. Again sometimes the editorpane looks blank. If I click on the list then some text are shown in the editor pane. Please help me to overcome these problems.
    Here goes the code for the renderer.
    list.setCellRenderer(new ListCellRenderer() {
                private JEditorPane editor = new JEditorPane();
                public Component getListCellRendererComponent(JList mList, Object value, int index,
                                                            boolean isSelected, boolean hasFocus) {
                    try {
                        editor.setPage("file://localhost/C:/networks/network1/description.html");
                        editor.setBackground(isSelected ? mList.getSelectionBackground() : mList.getBackground());
                        editor.setForeground(isSelected ? mList.getSelectionForeground() : mList.getForeground());
                        editor.setBorder(BorderFactory.createRaisedBevelBorder());
                        editor.setOpaque(true);
                    } catch(Exception e) {
                        e.printStackTrace();
                    return editor;
            });

    hai ahmad,
    it could be bcoz of the size of the pane.... the size content might be too large to fit in that pane....... y dont u increase the width of the pane..
    or set the size of the pane..... its surely bcoz of the size only....
    hope this helps u...... or else revert back for further clarifications...
    Regards,
    Ciya.

  • Missing the content when saving HTML from JEditorPane.write(..)

    hi,
    i m trying to develop html editor using JEditorPane. the document type used is HTMLDocument and HTMLEditorKit. when I try to save using the following function:
    try{
    FileWriter     w = new FileWriter("doc.html");
    //HTMLEditorKit edi = (HTMLEditorKit)editorPane.getEditorKit();
    EditorKit edi = editorPane.getEditorKit();
    //StyledEditorKit edi = new StyledEditorKit();
    //edi.write(w, (StyledDocument)editorPane.getDocument(), 0, editorPane.getDocument().getLength());
    editorPane.write(w);
    w.close();
    }catch(Exception de){System.out.println(de);
    }all the contents are missing, only the tags are intact in the output file doc.html. I am using JDK 1.4.2
    anybody can help me? thank you very much

    here is the code. hehe sorry lol it took me sometime to take off all the function. please try to type something and then save. only the update is saved but the default heading (well in this case, i have replace them all with a "something must be here". thank you very much
    // HTMLEditor.java
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    public class HTMLEditor extends JFrame{
      private JTextComponent textComp;
      public static void main(String[] args) {
        HTMLEditor editor = new HTMLEditor();
        editor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        editor.setVisible(true);
      public HTMLEditor() {
        super("Swing Editor");
        textComp = createTextComponent();
        Container content = getContentPane();
        content.add(textComp, BorderLayout.CENTER);
        content.add(createToolBar(), BorderLayout.NORTH);
        setSize(320, 240);
        Template t = new Template((HTMLDocument)(textComp.getDocument()));
        t.setupTemplate();
      // Override to create a JEditorPane with the HTMLEditorKit in place
      protected JTextComponent createTextComponent() {
        JEditorPane jep = new JEditorPane();
        jep.setEditorKit(new HTMLEditorKit2());
        JEditorPane.registerEditorKitForContentType
         ("text/html", "HTMLEditorKit2");
        return jep;
      protected JTextComponent getTextComponent() { return textComp; }
      // Add HTML actions to the toolbar
      protected JToolBar createToolBar() {
        JToolBar bar = new JToolBar();
        bar.addSeparator();
        bar.add(new StyledEditorKit.BoldAction());
        bar.add(new SaveAction());
        return bar;
      class SaveAction extends AbstractAction {
        public SaveAction() {
          super("Save", new ImageIcon("icons/save.gif"));
        // Query user for a filename and attempt to open and write the text
        // components content to the file
        public void actionPerformed(ActionEvent ev) {
          JFileChooser chooser = new JFileChooser();
          if (chooser.showSaveDialog(HTMLEditor.this) !=
              JFileChooser.APPROVE_OPTION)
            return;
          File file = chooser.getSelectedFile();
          if (file == null)
            return;
          FileWriter writer = null;
          try {
            writer = new FileWriter(file);
            textComp.write(writer);
          catch (IOException ex) {
            JOptionPane.showMessageDialog(HTMLEditor.this,
            "File Not Saved", "ERROR", JOptionPane.ERROR_MESSAGE);
          finally {
            if (writer != null) {
              try {
                writer.close();
              } catch (IOException x) {}
      class HTMLEditorKit2 extends HTMLEditorKit{
           public Document createDefaultDocument(){
             HTMLDocument doc = new HTMLDocument();;
             doc.setAsynchronousLoadPriority(-1); // load synchronously
             return doc;
    class Template{
         HTMLDocument doc;
         StyleContext styles = new StyleContext();
         public Template(HTMLDocument doc){
              this.doc= doc;
              Style def = styles.getStyle(StyleContext.DEFAULT_STYLE);
             Style heading = styles.addStyle("heading", def);
             StyleConstants.setFontFamily(heading, "SansSerif");
             StyleConstants.setBold(heading, true);
             StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER);
             StyleConstants.setSpaceAbove(heading, 10);
             StyleConstants.setSpaceBelow(heading, 10);
             StyleConstants.setFontSize(heading, 18);
         public void setupTemplate(){
              Style s = styles.getStyle("heading");
              try{
                   doc.insertString(doc.getLength(), "Something must be here", s);
                   doc.insertString(doc.getLength(), "\n", null);
                    doc.setLogicalStyle(doc.getLength() - 1, s);
              }catch(Exception e){}     
    }

  • Fail to use Jeditorpane to display a text with big5 encoding

    Hi All,
    I fail to use Jeditorpane to display a text with big5 encoding correctly.
    It only show machine code.
    I am using jre1.6.0_17. Yet it works well with earlier version of jre like jre 1.6.0_15, and jre 1.6.0_16
    bcpscsin

    bcpscsin wrote:
    ..I can find it in javax.swing
    FFS! It is JEditorPane, not Jeditorpane. Count the freaking upper case letters in both of those!
    Convince yourself by following these two URLs
    [http://java.sun.com/javase/6/docs/api/javax/swing/JEditorPane.html] -> produces a web page.
    [http://java.sun.com/javase/6/docs/api/javax/swing/Jeditorpane.html] -> "Page Not Found"
    My point is - do not type 'something like' the class name - get it right so we can be sure. Programming is a technical business and programmers need to be very accurate. It is even more important to be very accurate when asking for help on an forum. People have very little time to 'hold your hand' about the correct spelling and capitalisation of class names - or anything else for that matter.
    You still have not answered my question about the bug database.

  • Printing using JEditorPane !!!!

    hi,
    I have a trouble of printing using JEditorPane.its
    only prints first page of my HTML content.can you plz
    help me or you have the code for it its realy very
    useful for me.
    thanks in adv.
    regs,
    Stephan Noske

    A simple way is to break pages :
    1) read the HTML file
    2) break it in HTML pages
    3) send each page to print
    That's the solution I will use.

  • Problem to display Animated Gif from HTML into JEditorPane

    I have a problem displaying animated gif that comes from URL (HTML) into JEditorPane.
    Let me show you the source I have:
    * @author Dobromir Gospodinov
    * @version 1.0
    * Date: Dec 6, 2002
    * Time: 6:47:53 PM
    package test.advertserver;
    import javax.swing.*;
    import java.awt.*;
    import java.io.IOException;
    public class Test {
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              JEditorPane ed = new JEditorPane();
              try {
                   ed.setPage("http://localhost:8200/servlet?key=value");
              } catch (IOException e) {
                   e.printStackTrace();
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(500, 500));
              panel.add(ed);
              frame.getContentPane().add(panel);
              frame.pack();
              frame.setVisible(true);
    }Part of the returned from servlet HTML includes an img tag:
    <img src="/images/MyAnimatedGif.gif" alt="animated gif comment" width="480" height="50"  border="0">Let us assume that MyAnimatedGif.gif has 10 frames and gif is looped - when the 10th is dipslayed it has to display the 1st and so on.
    JEditorPane displays frames from 1 to 10 correctly but does not start from the first again. Instead JEditorPane displays a broken image.
    I locate where the problem arise:
    JEditorPane has an HTMLEditorKit that creates javax.swing.text.html.ImageView instance for every IMG tag.
    And here is the problem:
    ImageView has an ImageObserver necessary for the asynchronous image download. ImageObserver has the imageUpdate method. But this imageUpdate method is never called with ALLBITS flag raised up. Instead, after the last frame of MyAnimatedGif.gif is downloaded the imageUpdate method is called with flag ERROR raised up. Obviously this is a bug of Sun's implementation. Finaly the flag ALLBITS has to be received for normal end of image observing. But ALLBITS flag does not come.
    So, can anybody help me how to load an animated gif within JEditorPane completely.
    Thank You in advance,
    Dobromir Gospodinov
    P.S. If somebody of you wants to debbug what happens within ImageView will have to implement it (and related classes too, because of the limited package visability) borrowing the source from Sun's ImageView.

    I'm also having this problem with java 1.4.1 I discovered that some animated gifs work fine, while others stop animating. Running with java 1.3.1 fixed the problem. I'm going to report this as a bug
    Here's my code:
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    public class AnimatedGifTester
    extends JFrame
    public static void main(String argv[])
    throws Exception
    new AnimatedGifTester();
    public AnimatedGifTester()
    throws Exception
    String[] images = new String[] {
    "http://www.gif.com/ImageGallery/Animated/Animals/Photographic/dog_running.gif",
    "http://www.gif.com/ImageGallery/Animated/Characters/Cartoon/java.gif",
    "http://www.webdeveloper.com/animations/bnifiles/anielg.gif",
    "http://www.webdeveloper.com/animations/bnifiles/cat2.gif",
    "http://images.animfactory.com/animations/animals/fish/big_fish_swimming_md_wht.gif",
    "http://www.webgenies.co.uk/images/martian.gif",
    "http://www.webdeveloper.com/animations/bnifiles/at_sign_rotating.gif",
    "http://www.webdeveloper.com/animations/bnifiles/arrow_1.gif",
    "http://www.gif.com/ImageGallery/Animated/Characters/Cartoon/javaacro.gif",
    "http://java.sun.com/products/java-media/2D/samples/suite/Image/duke.running.gif",
    "http://www.gif.com/ImageGallery/Animated/SouthPark/Cartoon/stan.gif"
    StringBuffer buffer = new StringBuffer("<html><body>");
    for (int idx = 0; idx < images.length; idx++)
    buffer.append("<img src='" + images[idx] + "'>");
    buffer.append("</body></html>");
    String html = buffer.toString();
    // save a copy of the html to open in a browser so we can see what it's
    // supposed to look like
    BufferedWriter writer = new BufferedWriter(new FileWriter("animatedGifTest.html"));
    writer.write(html);
    writer.close();
    JEditorPane editorPane = new JEditorPane("text/html", html);
    editorPane.setEditable(false);
    getContentPane().add(editorPane);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(new Dimension(400, 600));
    show();

  • Code to translate xml data into html using jaxp ?

    Hi all !!
    Could you please send me code to translate xml data into html using jaxp
    i am sending my xml file and xsl file
    its urgent
    my xml file is :
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="scenario.xsl"?>
    <scenarioReport>
    <node name="node1">
    <netObjId>124 </netObjId>
    <result>undefined</result>
    <report>The cell is 124.</report>
    <action>qsdsqdqsd </action>
    </node>
    <node name="node 3">
    <netObjId>124 </netObjId>
    <result>undefined</result>
    <report>Result is unresolved because ...</report>
    <action>No action</action>
    </node>
    <node name="node 2">
    <netObjId>124 </netObjId>
    <result>undefined</result>
    <report>qsdqsdqs </report>
    <action>qsdsqd</action>
    </node>
    <node name="node 5">
    <netObjId>124 </netObjId>
    <result></result>
    <report> </report>
    <action> </action>
    </node>
    <node name="node 4">
    <netObjId>124 </netObjId>
    <result></result>
    <report> </report>
    <action></action>
    </node>
    </scenarioReport>
    my xsl file is::
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:template match="/">
    <html>
    <body>
    <h2> Scenario Report</h2>
    <table border="1">
    <tr bgcolor="#9acd32">
    <th align="left">Nodename</th>
    <th align="left">netObjId</th>
    <th align="left">Result</th>
    <th align="left">Report</th>
    <th align="left">Action</th>
    </tr>
    <xsl:for-each select="scenarioReport/node">
    <tr>
    <td><xsl:value-of select="@name"/></td>
    <td><xsl:value-of select="netObjId"/></td>
    <td bgcolor="#ffffff "><xsl:value-of select="result"/></td>
    <td><xsl:value-of select="report"/></td>
    <td><xsl:value-of select="action"/></td>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    Must be something wrong with your XSL.
    However apparently it was so urgent that you didn't have the time to look at what you posted. They just "fixed" the forum software and apparently it doesn't escape HTML that you type in any more. Or stuff that looks like HTML, either. So your post was unreadable.
    If your deadline hasn't passed, try reposting that code surrounded by [pre] and [/pre].

  • How to Create Test Sequence Document in HTML using command line

    How to Create Test Sequence Document  in HTML using command line
    I have lot of sequences and I want to create Test Sequence Documentation in HTML format using Command Line automatically, is there a way to automate this task using .bat file or using   C#  .Net

    If you aren't able to figure out how to call a C++ DLL in .net then there may be another option.  Unfortunately I don't know how to do this off the top of my head and I don't have an example.
    The other option would be to change docgen.seq a little bit to the dialog doesn't display and you just hardcode the options.  Then you can use a command line to call testexec.exe: http://zone.ni.com/reference/en-XX/help/370052K-01/tsfundamentals/infotopics/startup_opt/
    Hope this helps,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • How validate HTML using PL/SQL

    Hi,
    I try validate HTML using PL/SQL that user inputs.
    I did create below function for that purpose
    CREATE OR REPLACE
    FUNCTION validate_html(
      p_html IN VARCHAR2
    ) RETURN BOOLEAN
    AS
      l_comment  XMLTYPE;
      xml_parse_err EXCEPTION;
      PRAGMA EXCEPTION_INIT (xml_parse_err , -31011);
    BEGIN
      l_comment := xmlType.createXML('<root><row>' || p_html || '</row></root>');
      RETURN TRUE;
    EXCEPTION WHEN xml_parse_err THEN
      RETURN FALSE;
    END;
    Function works ok and return true if I run e.g.
    BEGIN
      IF validate_html('<p>Hello</p>') THEN
        dbms_output.put_line('OK');
      ELSE
        dbms_output.put_line('Not valid HTML');
      END IF;
    END;
    And return false if I enter not valid HTML like
    BEGIN
      IF validate_html('<p>Hello') THEN
        dbms_output.put_line('OK');
      ELSE
        dbms_output.put_line('Not valid HTML');
      END IF;
    END;
    But it return false also if I run below
    BEGIN
      IF validate_html('<p>Hello &nbsp</p>') THEN
        dbms_output.put_line('OK');
      ELSE
        dbms_output.put_line('Not valid HTML');
      END IF;
    END;
    Problem seems to be that &nbsp (there is ; in end but do not know how post it without forum convert that to space) witch is valid HTML for me.
    I know that HTML is not XML, but can I use Oracle database XML functions for validating HTML?
    How I should validate user inputted HTML?
    I'm currently developing this using Oracle XE 11G database.
    Regards,
    Jari

    Not an elegant way:
    But try this.........
    CREATE OR REPLACE FUNCTION validate_html (p_html IN VARCHAR2)
       RETURN BOOLEAN AS
       l_comment       XMLTYPE;
       xml_parse_err   EXCEPTION;
       PRAGMA EXCEPTION_INIT (xml_parse_err, -31011);
    BEGIN
       l_comment :=
          xmlType.createXML (
             '<root><row>'
             || CASE
                   WHEN INSTR (p_html, '&') > 0 THEN
                      UTL_I18N.escape_reference (p_html)
                   ELSE
                      p_html
                END
             || '</row></root>');
       RETURN TRUE;
    EXCEPTION
       WHEN xml_parse_err THEN
          RETURN FALSE;
    END;
    SET DEFINE OFF
    SET SERVEROUTPUT ON
    BEGIN
       IF validate_html ('<p>Hello') THEN
          DBMS_OUTPUT.put_line ('OK');
       ELSE
          DBMS_OUTPUT.put_line ('Not valid HTML');
       END IF;
    END;
    SET DEFINE OFF
    SET SERVEROUTPUT ON
    BEGIN
       IF validate_html ('<p>Hello &nbsp</p>') THEN
          DBMS_OUTPUT.put_line ('OK');
       ELSE
          DBMS_OUTPUT.put_line ('Not valid HTML');
       END IF;
    END;
    Cheers,
    Manik.

  • Parsing HTML using Swing's HTMLEditorKit

    Hi all,
    I posted this question on the "Java programming", but I think I posted on the wrong forum. So, please let me know if I have posted on the wrong forum, again.
    Anyway, I have read an article on parsing HTML using the Swing HTML Parser (http://java.sun.com/products/jfc/tsc/articles/bookmarks/index.html). However, I find that the HTMLEditorKit is unable to understand the <Meta> tag under the <Head> tag? Is this true? I am getting an error message:
    javax.swing.text.ChangedCharSetException
    at javax.swing.text.html.parser.DocumentParser.handleEmptyTag(DocumentParser.java:172)
    at javax.swing.text.html.parser.Parser.startTag(Parser.java:327)
    at javax.swing.text.html.parser.Parser.parseTag(Parser.java:1786)
    at javax.swing.text.html.parser.Parser.parseContent(Parser.java:1821)
    at javax.swing.text.html.parser.Parser.parse(Parser.java:1980)
    at javax.swing.text.html.parser.DocumentParser.parse(DocumentParser.java:109)
    at javax.swing.text.html.parser.ParserDelegator.parse(ParserDelegator.java:74)
    at URLReader.main(URLReader.java:58)
    Below is a simple code to write out the html file it reads in:
    public static void main(String[] args) throws Exception {
    HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback () {
    public void handleText(char[] data, int pos) {
    try {
    System.out.println(data);
    } catch (Exception e) {
    System.out.println("IOE: " + e);
    Reader reader = new FileReader("myFile.html");
    new ParserDelegator().parse(reader, callback, false);
    The html file that is having a problem reading in is:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>NWS WSR-88D Radar System Transmit/Receive Status</title>
    </head>
    <p>A <foo>xx</foo>link</html>
    If I take away <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">, there is no problem.
    Any suggestions? Thanks in advance.

    Hi,
    Setting the third argument really works!!! Yee..... haa....!!!
    WORKING SOLUTION: new ParserDelegator().parse(reader, callback, TRUE);
    MANY... MANY THANKS for looking at the problem!!!
    Send third argument in parse method as true.

  • Have to use JEditorPane?

    Hello,
    I designed a chat client. The window that all the output (IE "rajatbanerjee: hello\n") is held in is a non-editable field.
    RIght now i have a TextArea.
    The problem is , i want to add colors and BOLD to this, just to spice it up a little. Do i have to use JEditorPane or JTextPane?
    THey are an awful pane (hahaha) to set up. Thank you,
    Rajat Banerjee

    You would probably use a JTextPane. Its not that hard. Here's a thread to get you started:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=342068

Maybe you are looking for