JTidy Problem

K

k4

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 ?
 
K

k4

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 :(
 
T

Tom Hawtin

k4 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top