🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #10353

HTML parser for HTML tags

#10353
From: Harald Binkle
Date: Wed, 06 Oct 1999 00:00
55 lines
2079 bytes
Hello,
i'd like to built a parser for HTML tags. But I can only pars links.

-----------------------------------------------
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.util.*;
import java.net.*;
import java.io.*;


public class test{

    public static void main (String[] args){
        String arg = args[0];

        URLConnection conn;
        HTMLEditorKit kit = new HTMLEditorKit();
        Document doc = kit.createDefaultDocument();
        // The Document class does not yet handle charset's properly.
        doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
        try{
            URL page = new URL(arg);
            conn = page.openConnection();
            conn.connect();
            InputStreamReader isr = new
InputStreamReader(conn.getInputStream());
            kit.read(isr,doc,0);
            isr.close();
            String link = "doc.length: "+doc.getLength()+"\n\n";
            ElementIterator it = new ElementIterator(doc);
            javax.swing.text.Element elem;
            int i=0;
            while ((elem = it.next()) != null) {
                    SimpleAttributeSet s1 =
(SimpleAttributeSet)elem.getAttributes().getAttribute(HTML.Tag.A);///META,HEAD
etc.
     link = link + s1+"\n";
            }

 System.out.println(link);

        }
        catch(Exception e){
            System.out.println("Error: " +e.toString());
        }
    }

}
----------------------------------------
if I put BODY or META instead of A i get null why?

Can you help me?

Harry
Technical Details
Message-ID: <37FB6D3F.FCAEF334@ti.fhg.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,aaa834f0fb38d9b4,start
X-Google-Attributes: gid111d45,public
From: Harald Binkle <binkle@ti.fhg.de>
Subject: HTML parser for HTML tags
Date: 1999/10/06
Message-ID: <37FB6D3F.FCAEF334@ti.fhg.de>
X-Deja-AN: 533508418
Content-Transfer-Encoding: 7bit
Organization: Fraunhofer Gesellschaft
X-Accept-Language: de
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing