• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTIDY Document to JDOM Document

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I am using JTIDY to convert a HTML into XML.
I don't want to save xml to file and I wan't to use org.jdom.Document instead of org.w3c.dom.Document.
I tryed to convert the generated file using the code at:
http://www-106.ibm.com/developerworks/java/library/x-tipcdm.html and it works fine.
But this convert from an xml-file and not a org.w3c.dom.Document.
Anyone who knows how I do that?

This is the code for reading HTML.
import java.io.*;
import java.net.URL;
import org.w3c.dom.Document;
import org.w3c.tidy.Tidy;

public class LoadDOM implements Runnable {
private String url;
private String outFileName;
private String errOutFileName;
private boolean xmlOut;

public LoadDOM(String url, String outFileName,
String errOutFileName, boolean xmlOut) {
this.url = url;
this.outFileName = outFileName;
this.errOutFileName = errOutFileName;
this.xmlOut = xmlOut;
}

public void run() {
URL u;
BufferedInputStream in;
FileOutputStream out;
Tidy tidy = new Tidy();
tidy.setConfigurationFromFile("D:\\jtidy.conf");
tidy.setXmlOut(xmlOut);

try {
tidy.setErrout(new PrintWriter(new FileWriter(errOutFileName), true));
u = new URL(url);
in = new BufferedInputStream(u.openStream());
out = new FileOutputStream(outFileName);
Document doc = tidy.parseDOM(in, out); //I wan't to convert this
//org.w3c.dom.Document to
//a org.jdom.Document
System.out.println("File saved to:" + outFileName);
} catch (IOException ex) {
ex.printStackTrace();
}
}

public static void main(String[] args) {
LoadDOM t1 = new LoadDOM("http://www.myPage.com",
"D:\\myPage.xml",
"D:\\myPage_error.txt", true);
Thread th1 = new Thread(t1);
th1.start();
}
}
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello gorby, and welcome to the JavaRanch!

I noticed that your display name is missing a last name/first name, and thus is violating our naming policy -- May I ask you to edit your display name accordingly. Thanks.
 
Gorby Green
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solve the problem.
/Gorby
 
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic