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 "Lalazar, Hagai" <Ha...@us.loquendo.com> on 2002/01/09 01:15:40 UTC
How to: Initialize DOMParser (html dom) to parse xHTML?
Hi.
I'm using DOMParser to parse xHTML docs, but can't seem to get the
"dom/document-class-name" property, when set to building an html DOM, to
co-exist with the declarations at the top of an xHTML document.
My parser initialization is as follows:
DOMParser parser = new DOMParser();
// turn parser xml validation off
parser.setFeature("http://xml.org/sax/features/validation
<http://xml.org/sax/features/validation> ", false);
// request an HTML dom, instead of the generic dom
parser.setProperty("http://apache.org/xml/properties/dom/document-class-
name <http://apache.org/xml/properties/dom/document-class-name> ",
"org.apache.html.dom.HTMLDocumentImpl");
parser.parse(newDoc);
And this is the top of my xHTML doc (as prescribed by the w3c spec:
http://web3.w3.org/TR/xhtml1/#docconf) :
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> ">
<html xmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>
">
.
.
Once I added the "dom/document-class-name" setProperty( ) call to my
code, the parser started choking on the first lines of the doc. Changing
those three lines to simply: "<html>" (and changing my Character Entity
References to their hexadecimal literals) made the problems disappear
(see below for the exceptions I got). It seems like Xerces dom.html
implementation excludes an xHTML doc as input. However, this should be a
sound thing to do as the xhtml1-transitional.dtd is just an XML-ized
HTML 4.
Does anyone know of the proper way to resolve this?
Here are the test cases and exceptions I received:
1) As is, I get:
org.xml.sax.SAXParseException: The attribute type is required in the
declaration of attribute "even
ts" for element "html".
2) If I remove the DOCTYPE declaration, I get:
org.w3c.dom.DOMException: DOM003 Namespace error
3) If I remove the xml-namespace attribute, from the html element, I
get:
org.xml.sax.SAXParseException: The attribute type is required in the
declaration of attribute "even
ts" for element "html".
4) Removing the DOCTYPE and the "xmlns" attribute yields:
org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but
not declared.
Thanks for your help,
Hagai Lalazar.
Loquendo, Inc.
Hagai.Lalazar@us.loquendo.com <ma...@us.loquendo.com>
(415) 615-0600 x314