JTidy Problem

Discussion in 'Java' started by k4, Apr 2, 2007.

  1. k4

    k4 Guest

    Hi

    I have problem with JTidy, I can't return text between <p> xx </p> :/


    import org.w3c.dom.Document;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.tidy.Tidy;


    public static void main(String[] args) {

    try {
    Tidy tdpr = new Tidy();
    Document dc;

    tdpr.setShowWarnings(false);
    tdpr.setXHTML(true);

    FileInputStream zoo = new FileInputStream("index.html");
    BufferedInputStream in = new BufferedInputStream(zoo);
    BufferedOutputStream out = new BufferedOutputStream(new
    FileOutputStream("bar.html"));

    dc = tdpr.parseDOM(in, null);
    NodeList tag = dc.getElementsByTagName("p");
    System.out.print(tag.getLength());
    Node uchwyt = tag.item(0);
    System.out.print(uchwyt.getFirstChild().getTextContent());

    }catch (Exception z) {}

    any idee ?
    k4, Apr 2, 2007
    #1
    1. Advertising

  2. k4

    k4 Guest

    k4 napisa³(a):
    > Hi
    >
    > I have problem with JTidy, I can't return text between <p> xx </p> :/
    >
    >
    > import org.w3c.dom.Document;
    > import org.w3c.dom.Node;
    > import org.w3c.dom.NodeList;
    > import org.w3c.tidy.Tidy;
    >
    >
    > public static void main(String[] args) {
    >
    > try {
    > Tidy tdpr = new Tidy();
    > Document dc;
    >
    > tdpr.setShowWarnings(false);
    > tdpr.setXHTML(true);
    >
    > FileInputStream zoo = new FileInputStream("index.html");
    > BufferedInputStream in = new BufferedInputStream(zoo);
    > BufferedOutputStream out = new BufferedOutputStream(new
    > FileOutputStream("bar.html"));
    >
    > dc = tdpr.parseDOM(in, null);
    > NodeList tag = dc.getElementsByTagName("p");
    > System.out.print(tag.getLength());
    > Node uchwyt = tag.item(0);
    > System.out.print(uchwyt.getFirstChild().getTextContent());
    >
    > }catch (Exception z) {}
    >
    > any idee ?



    My error:
    Exception in thread "main" java.lang.AbstractMethodError:
    org.w3c.tidy.DOMElementImpl.setTextContent(Ljava/lang/String;)V

    Why ???? All day i spend time to run this Jtidy :(
    k4, Apr 2, 2007
    #2
    1. Advertising

  3. k4

    Tom Hawtin Guest

    k4 wrote:
    > My error:
    > Exception in thread "main" java.lang.AbstractMethodError:
    > org.w3c.tidy.DOMElementImpl.setTextContent(Ljava/lang/String;)V


    That's a /little/ more information than "I can't return text between <p>
    xx </p>".

    AbstractMethodError API docs say:

    "Thrown when an application tries to call an abstract method. Normally,
    this error is caught by the compiler; this error can only occur at run
    time if the definition of some class has incompatibly changed since the
    currently executing method was last compiled."


    Essentially you've called an abstract method (as interface methods are)
    and the implementing class hasn't implemented it. How? Probably it was
    compiled with an earlier version of the interface that didn't have that
    method.

    API docs for Node.setTextContent/getTextContent:

    "Since:
    DOM Level 3"

    JTidy doesn't support DOM Level 3 (or fully support Level 2 come to
    that). So you need to use the old school methods, which I believe is to
    iterate through the tree looking for Text nodes.

    Tom Hawtin
    Tom Hawtin, Apr 2, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike

    USE OF JTIDY SYSTEM!!

    mike, May 5, 2004, in forum: Java
    Replies:
    0
    Views:
    355
  2. mike
    Replies:
    0
    Views:
    472
  3. mike
    Replies:
    1
    Views:
    436
  4. mike
    Replies:
    2
    Views:
    458
  5. mike

    A Jtidy question

    mike, Oct 26, 2004, in forum: Java
    Replies:
    2
    Views:
    438
Loading...

Share This Page