You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Paul Green <Pa...@ons.gsi.gov.uk> on 2005/10/05 14:14:33 UTC

Parsing HTML

Hi,

I read recently (in Elliotte Rusty Harold's "Processing XML with Java")
that Xerces-J is capable of parsing an HTML document into a DOM tree.
Xerces-J 1.4.4 does indeed contain an "html" package with all the required
interfaces to represent an HTML document in DOM form. However, I have been
unable to determine how to set up the DOM parser to create such a document,
despite an extensive search. I would be grateful if someone could point me
at any documentation, and particularly code examples, describing how to do
this. Alternatively, if i'm barking up the wrong tree, which tree should I
go and bark up?

Regards,

Paul Green




For the latest data on the economy and society 
consult National Statistics at http://www.statistics.gov.uk

**********************************************************************
Please Note:  Incoming and outgoing email messages
are routinely monitored for compliance with our policy
on the use of electronic communications
**********************************************************************
Legal Disclaimer  :  Any views expressed by
the sender of this message are not necessarily
those of the Office for National Statistics
**********************************************************************

The original of this email was scanned for viruses by the Government Secure Intranet (GSi) virus scanning service supplied exclusively by Energis in partnership with MessageLabs.

On leaving the GSi this email was certified virus-free

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Parsing HTML

Posted by Andy Clark <an...@apache.org>.
Paul Green wrote:
> I read recently (in Elliotte Rusty Harold's "Processing XML with
> Java") that Xerces-J is capable of parsing an HTML document into a
> DOM tree. Xerces-J 1.4.4 does indeed contain an "html" package with
> all the required interfaces to represent an HTML document in DOM
> form. However, I have been unable to determine how to set up the DOM
> parser to create such a document, despite an extensive search. I
> would be grateful if someone could point me at any documentation, and
> particularly code examples, describing how to do this. Alternatively,
> if i'm barking up the wrong tree, which tree should I go and bark up?

I haven't read the Man-With-Three-First-Names's article
but the core Xerces package does not support HTML parsing
out of the box. The HTML DOM packages are just an
implementation of the HTML interfaces of the W3C DOM spec.
That being said, there is still a way to parse HTML using
Xerces, though.

I have a side project called NekoHTML that builds on the
Xerces Native Interface (XNI) and implements an HTML
scanner and tag-balancer. This allows you to parse HTML
documents and treat the results as XML, with all of the
parsing APIs available in Xerces (e.g. DOM and SAX).

Here's the link where you can download and evaluate it:

   http://www.apache.org/~andyc/neko/doc/html/

Another option for parsing HTML and using XML interfaces
is JTidy. It's primarilly used for cleaning up HTML and
saving the result back to a file but it also supports a
DOM result.

There are a number of other HTML parsers available but
I have less experience with them and, from what I've
seen, most have custom programming interfaces.

So evaluate a few of the available options and choose
the one that works best for you and what you need to do.

-- 
Andy Clark * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org