Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I hope here is somebody who knows and uses Dom4j library for Java. I have an assignment for tomorrow, but have achieved almost nothing. So, I need your help.

Using Dom4j library, I am asked to parse an HTML document, then create a .dot file for its DOM tree. This file in DOT language will be used by GraphViz application. Here, I'll consider just text nodes of the file.

Parsing an HTML document is okay using the library's built-in functions. I can see a text node's parent in the debugging mode of Eclipse. But I cannot write these data over a .dot file in the syntax of DOT language via an output steam defined in the type of PrintWriter.

First, in the block of public void visit(Text text) method, I tried to create a new .dot file via the steam. Then, I tried to write "digraph G{\n" over the file as a beginning for the document. Then, I put the following line to construct the syntax of "(parent node) -> (child node);" in DOT language for each parent-child pair in the DOM tree.

writer.println(text.getParent().getStringValue() + "->" + text.getStringValue() + ";");

But this line first writes the entire document over the .dot file, then puts a "->" and a ";" as I've written in the code.

I hope you get the issue. What can I do here? Thank you in advance.
Posted
Updated 2-Jul-14 4:37am
v2

1 solution

THE THREAD CAN BE CLOSED.

I've solved the problem.

:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900