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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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>
<?xml version="1.0" encoding="UTF-8" ?>
body
</body>
</html>
The XML declaration is escaped and then put into body.
That's because HTML is expected as input, not XML.
Vladmimir.
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.
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.
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?
It seems it is still present even in HTMLCleaner 2.0. Could this be fixed? Thanks in advance!
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