W3C home > Mailing lists > Public > html-tidy@w3.org > April to June 2001

jtidy question

From: Daniel F Lim <limd@cs.ucdavis.edu>
Date: Tue, 29 May 2001 12:14:44 -0400 (EDT)
To: html-tidy@w3.org
Message-ID: <Pine.HPP.4.10.10105290911590.1200-100000@hp9.cs.ucdavis.edu>

i'm working with your jtidy package and the parser seems to work fine.
i'm currently trying to parse an HTML file using jtidy.parseDOM.  with the
resulting DOM tree structure i try to create new elements and rearrange
the tree but i continue to have problems.

import java.io.*;
import org.w3c.dom.*;
import org.w3c.tidy.*;

public class JtidyTest {
public static void main(String args[]) throws Exception {
        String str = "<html><head><title>test</title></head>\n";
        str = str.concat("<body bgcolor=#FFFFFF><font size=\"3\">\n");
        str = str.concat("this</font> is strange ?</body></html>\n");
        BufferedInputStream in = new BufferedInputStream(new

        Tidy tidy = new Tidy();
        tidy.setErrout(new PrintWriter(new FileWriter("errors"),true));
        Document root = tidy.parseDOM(in,new

        org.w3c.dom.Node target = root.getFirstChild().getFirstChild();

        Element anchor = root.createElement("a");
        anchor.setAttribute("href", "http://www.google.com");
        target.getParentNode().insertBefore(anchor, target);

        tidy.pprint(root, System.out);

this produces:

<a href="http://www.google.com" />
<meta name="generator" content="HTML Tidy, see www.w3.org" />
<body bgcolor="#FFFFFF">
<font size="3">this</font> is strange ?

but shouldn't the <a href="http://www.google.com"> element surround the
<head> element instead of being a separate element?  shouldn't it produce
the following:

<a href="http://www.google.com">
<meta ...>

Received on Tuesday, 29 May 2001 12:51:50 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:38:50 UTC