Re: parsing xHTML

Jacob Kjome <[email protected]> Mon, 15 Sep 2003 02:03:15 -0500
Newsgroups gmane.comp.java.enhydra.xmlc
Message-ID <[email protected]>
The XHTML spec, unlike the HTML spec, requires a DTD to be defined.  So, 
yes, you need a dtd.  You should also, as a good practice, use a dtd for 
HTML documents.  Here's a template for XHTML documents (view the source of 
the email if you client mangles the pasted XHTML tags)...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
         PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
<head>
     <title>XHTML 1.0 Strict Template</title>
     <meta http-equiv="Content-Type" content="application/xml+xhtml; 
charset=UTF-8"/>

Verify that your XMLC template is valid XHTML using...
http://validator.w3.org/

Then compile with...

-dom xhtml -parser xerces

Jake

At 10:39 PM 9/14/2003 -0700, you wrote:
>When I add '-domfactory org.enhydra.xml.xhtml.XHTMLDomFactory' I see:
>
>file:///foo.html:2: Error: Element type "html" must be declared.
>file:///foo.html:3: Error: Element type "body" must be declared.
>file:///foo.html:4: Error: Element type "table" must be declared.
>file:///foo.html:5: Error: Element type "tr" must be declared.
>file:///foo.html:6: Error: Element type "td" must be declared.
>file:///foo.html:6: Error: Element type "img" must be declared.
>file:///foo.html:6: Error: The element type "img" must be terminated by 
>the matching end-tag "</img>".
>Error: Parse of "foo.html" failed: org.xml.sax.SAXException: Stopping 
>after fatal error: The element type "img" must be terminated by the 
>matching end-tag "</img>".
>
>Do I need some kind of DTD declaration in my HTML?
>   Thanks,
>    -M@
>
>On Sunday, September 14, 2003, at 06:02  PM, Jacob Kjome wrote:
>
>>
>>By default, XMLC uses an HTML parser.  Try using "-dom xhtml" or doing 
>>"-domfactory org.enhydra.xml.xhtml.XHTMLDomFactory" (which is 
>>functionally the same as the former) ...or use "-domfactory 
>>org.enhydra.xml.xhtml.HTMLDomFactory which is almost the same as the 
>>XHTMLDomFactory, but defaults to the text/html mime type where the former 
>>defaults to application/xml+xhtml and the most classes implement 
>>HTMLElement rather than the custom XHTML element interfaces.  Just 
>>depends on your needs.
>>
>>You probably also need to specify a different parser which supports 
>>XML.  Try using "-parser xerces".  It is actually the jtidy parser (which 
>>only understands HTML, not XML) which is "fixing" up your invalid HTML.
>>
>>Jake
>>
>>At 03:35 PM 9/14/2003 -0700, you wrote:
>>>I was playing around with XMLC a bit this afternoon and discovered that 
>>>XMLC was outputting incorrect HTML when my input HTML was a well formed 
>>>XML doc.  For example, I'd close my <img> tags like so:
>>>
>>><img src="foo.png" alt=""/>
>>>
>>>With this inside a <td> element XMLC was choosing to open the next <td> 
>>>instead of following the <img> tag with </td>.  Anyway, I fixed it by 
>>>writing non-well formed HTML.  Is there a way to get XMLC to do the 
>>>right thing when I write xHTML?
>>>   Thanks,
>>>    -M@
>>>
>>>_______________________________________________
>>>XMLC mailing list
>>>[email protected]
>>>http://www.enhydra.org/mailman/listinfo.cgi/xmlc
>>
>>_______________________________________________
>>XMLC mailing list
>>[email protected]
>>http://www.enhydra.org/mailman/listinfo.cgi/xmlc
>
>_______________________________________________
>XMLC mailing list
>[email protected]
>http://www.enhydra.org/mailman/listinfo.cgi/xmlc