RE: [xml] correct way to output HTML without the <?xml...



Nic,

An XML document instance must have an xml declaration otherwise it is not
valid XML.  If you want to have no xml declaration you need to output SGML.
Only SGML documents allow not declaration as the very first line in the
document.  I'm not sure how to get SGML output using libxml2 but .  Your
"-//W3C//DTD HTML 4.01 Transitional//EN" doctype is SGML.  Maybe your
statement about "xml_output_buffer" is wrong.  Is there an
'sgml_output_buffer' in libxml2 that you could use?

I hope that this helps.


John

-----Original Message-----
From: xml-bounces gnome org [mailto:xml-bounces gnome org] On 
Behalf Of Nic James Ferrier
Sent: Wednesday, 24 May 2006 3:10 AM
To: libxml
Subject: [xml] correct way to output HTML without the <?xml...


I've got a libxml2 DOM with HTML in it (note: it's just an XML DOM
with HTML in it).

I want to output it as well-formed HTML, preferably with the HTML4
transitonal DTD but no xml declaration, eg:

  <DOCTYPE HTML ...>
  <html>
    <head>
      <link rel="xxx" .../>
    </head>
    .
    .
    .
  </html>

I'm not sure of the right way to achieve this.

I tried this:

    htmldoc = libxml2.newDoc("1.0")
    html4_transitional = htmldoc.newDtd("HTML", "-//W3C//DTD 
HTML 4.01 Transitional//EN",
                                        
"http://www.w3.org/TR/html4/loose.dtd";)
    htmldoc.addChild(html4_transitional)
    .
    .
    .
    xml_output_buffer.htmlDocContentDumpFormatOutput(htmldoc, 
"utf-8", 1)

but that spits out HTML without the DTD or a well-formed DOM.


Outputting with:

   xml_output_buffer.saveFormatFileTo(htmldoc, 'UTF-8', 1)

outputs the XML including the XML declaration, which I don't want
since this is well-formed HTML.


Anybody know the right way to go about this?


Nic
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]