Задача: дан HTML, не целостный и не well-formed.
Сделать из него well-formed XHTML. На Java.
Заказчик предполагал JTidy, но оно отстойное. Искал парсер, чтобы валидировать XML (не в смысле схемы, а в смысле - исправлять ошибки написания) и выдавать well-formed XML и список ошибок.
Нашел упоминание о том, что JTidy - единственная, а OpenXML, который тоже был, ушёл в xalan/xerces. Правда, не было ясно, мержировали ли собственно парсер. Изучив работу Xerces с включенной property continue-after-fatal-error, сделал вывод - нет, не мержировали. Он восстанавливает HTML content совсем не понимая контекста, например, так: из br text br text делает br text br text /br text /br text. Well-formed XML, но не HTML.
А вот от заказчика приползло возможное решение: TagSoup.
Текст моего отзыва: IMHO, its sources look clean, author looks competent, API is simple, product is actively maintained (maillist is quite active) and mentioned test set is impressive (as said, 8% of those broken test pages are still not parsed correctly, but still output is well-formed).
Command-line testing resulted in well-formed XML in every case I tried except for nasty <script> tag tricks like
Though, it misses detailed documentation (even has no javadoc comments), and as presentation document says, unlike JTidy does not convert markup to CSS. This may result in still non-conformance to XHTML DTD. Specific XHTML DTD conformance is not guaranteed also (but still output is well-formed).
In general, I would use TagSoup if I had to validate. It's nice to have JTidy alternative.
Сделать из него well-formed XHTML. На Java.
Заказчик предполагал JTidy, но оно отстойное. Искал парсер, чтобы валидировать XML (не в смысле схемы, а в смысле - исправлять ошибки написания) и выдавать well-formed XML и список ошибок.
Нашел упоминание о том, что JTidy - единственная, а OpenXML, который тоже был, ушёл в xalan/xerces. Правда, не было ясно, мержировали ли собственно парсер. Изучив работу Xerces с включенной property continue-after-fatal-error, сделал вывод - нет, не мержировали. Он восстанавливает HTML content совсем не понимая контекста, например, так: из br text br text делает br text br text /br text /br text. Well-formed XML, но не HTML.
А вот от заказчика приползло возможное решение: TagSoup.
Текст моего отзыва: IMHO, its sources look clean, author looks competent, API is simple, product is actively maintained (maillist is quite active) and mentioned test set is impressive (as said, 8% of those broken test pages are still not parsed correctly, but still output is well-formed).
Command-line testing resulted in well-formed XML in every case I tried except for nasty <script> tag tricks like
<script ..> document.write("</script>") </script>, but the latest maillist letters already address this problem and author is working on it.Though, it misses detailed documentation (even has no javadoc comments), and as presentation document says, unlike JTidy does not convert markup to CSS. This may result in still non-conformance to XHTML DTD. Specific XHTML DTD conformance is not guaranteed also (but still output is well-formed).
In general, I would use TagSoup if I had to validate. It's nice to have JTidy alternative.
Tags:
(no subject)
8/11/06 18:36 (UTC)