Re: [xml] Possible to get XHTML output from HTMLparser?
- From: "Martin (gzlist)" <gzlist googlemail com>
- To: "R. Steven Rainwater" <srainwater ncc com>
- Cc: xml gnome org
- Subject: Re: [xml] Possible to get XHTML output from HTMLparser?
- Date: Sat, 20 Dec 2008 12:25:57 +0000
On 19/12/2008, R. Steven Rainwater <srainwater ncc com> wrote:
I'm using libxml2 for an application that generates XHTML output. I've
recently needed to parse some nasty HTML tag soup input and incorporate
it into some of my pages. Libxml2's HTMLparser does a great job of
fixing up the bad HTML but it outputs HTML v4 markup. Is there any
existing function that will output XHTML markup from the HTMLparser?
... I'm assuming I'd just need to walk the HTMLparser output
tree, closing empty elements, expanding stand-alone attributes, and
such. Looks like HTMLparser already fixes some things like making sure
attribute values are quoted.
Those are serialisation details that the tree doesn't care about.
In libxml2 htmlDoc objects *are* xmlDoc objects, so if you just care
about well-formedness any of the normal XML functions will do. Will
need to walk the tree to set the correct the namespace on all the
nodes however.
If you also care about validity according to a particular XHTML DTD,
you'd have to do considerable tree modifications to turn arbitrary tag
soup into something correct. Browsers have complex heuristics to, for
instance, make sanity out of form elements inside tables.
Martin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]