Menu

Problems with XML declaration in XHTML

TomB
2007-12-04
2013-03-05
  • TomB

    TomB - 2007-12-04

    I'm using HtmlCleaner 1.55 a have some problems with XHTML. From:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>xml declaration test</title>
    </head>
    <body>body</body>
    </html>

    using following code:

    cleaner=new HtmlCleaner(...);
    cleaner.setOmitXmlDeclaration(true);
    cleaner.clean();
    cleaner.writePrettyXmlToFile(...);

    I've got:

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs" xmlns:xml="xml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            <title>xml declaration test</title>
        </head>
        <body>
            &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
            body
        </body>
    </html>

    The XML declaration is escaped and then put into body.

     
    • Vladimir Nikic

      Vladimir Nikic - 2007-12-04

      That's because HTML is expected as input, not XML.

      Vladmimir.

       
      • TomB

        TomB - 2007-12-04

        I am currently using HtmlCleaner for HTMLs and Java's DocumentBuidler for XMLs or valid XHTMLs. Unfortunatelly, I have to handle some invalid XHTML with such XML declaration, where XML parsers failed. When using HtmlCleaner, I have to postprocess the clean method with regexp (in order to remove XML declaration). I'll we happy, if this cleaning can be performed before (or during) the parsing.

         
        • Vladimir Nikic

          Vladimir Nikic - 2007-12-04

          I'll check what web browsers are doing when they encounter XML declaration inside HTML document. If they remove it, I'll add that to HtmlCleaner as well.

          Vladimir.

           
          • Martin Zdila

            Martin Zdila - 2008-03-17

            Hello. I have the same issue. Check for example http://www.joj.sk. XHTML is actually also XML document. Why couldn't it have the XML declaration then?

             
            • Martin Zdila

              Martin Zdila - 2008-05-15

              It seems it is still present even in HTMLCleaner 2.0. Could this be fixed? Thanks in advance!

               
      • Vincent Massol

        Vincent Massol - 2008-12-15

        I have this exact same problem where:

        <?xml version="1.0" encoding="UTF-8"?>
        <html><head /><body>one two three<br/><br/>hello</body></html>

        gets transformed into:

        <?xml version="1.0" encoding="UTF-8"?>
        <html><head /><body><?xml version="1.0" encoding="UTF-8"?>
        one two three<br /><br />hello</body></html>

        You say that HTML Cleaner only accepts HTML as input. I'd also like to take XHTML as input and clean it if it has problems.

        How is it different to accept HTML and not XHTML?

        Could this be fixed?

        Thanks
        -Vincent

         

Log in to post a comment.