Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xml-dev] Parsing bad HTML

From: "Steven J. DeRose" <sderose@---.--->
To: xml-dev@-----.---.---
Date: 11/14/2008 12:56:00 AM
I'd say there are two questions you have to decide before you can 
tell the best approach:

1: What do you *want* that to parse to?

2: What other cases do you need to deal with?

For #1, I'd assuming that you want "67<eight" to be treated as if it 
were "67&lt;8", and you want the pointies inside the alt attribute to 
really be there, presumably also via &lt; (you might instead want to 
strip the "b" pseudo-tags entirely, or insert an "<eight>" tag for 
some reason, or....

For #2, is there a recurring pattern/problem you need fixed? If not, 
then there's no point in *programming* a solution of any kind. If so, 
what *is* the pattern? From this example it might be that you want to 
treat a less-than as literal data instead of a tag-start in any one 
of these situations:

a) after a sequence of digits

b) before "eight" (or before "e", or before any spelled-out name of a 
number, or....)

c) whenever the following text can't form a well-formed tag (this 
might be too draconian, though)

d) whenever the following XML Name characters (in this case "eight") 
don't form a known HTML tag name.

As is always true, a finite number of examples can be accounted for 
by an infinite number of different models; but to implement something 
you have to take your pick. If there's a lot of data involved, you 
would be well advised to scan around it and determine what kinds of 
errors there are,  then solve the most frequent ones first.

On the whole, this looks to me like the sort of thing you either fix 
by hand (if there are few enough examples, or if the examples are 
totally unpredictable); or by some simple regexes, such as:

sed 's/<\([a-zA-Z]*\)</\&lt;\1</g

Steve

At 12:22 PM -0800 11/13/08, Paul M wrote:
>I use tidy to clean up  bad html docs. It does a pretty good job of 
>converting html => strict xthml
>
>However, the following is a bit too much
>
><p>
><sub>123</sub>4567<eight<img src="file.gif" alt="<b>hello</b>">
></p>
>
>The problem is with 7<eight. Stray < and > seem to make tidy choke. 
>What is the best method of handling this? I am leaning toward perl 
>and regexp, but am hoping to avoid this. Maybe a Java solution? And 
>tidy solutions?
>
>-thanks


-- 

Steve DeRose -- http://www.derose.net, email sderose@a...


_______________________________________________________________________

XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.

[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@l...
subscribe: xml-dev-subscribe@l...
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent