In my kid template I have this following line: <div class="reviewitem" py:content="XML(review.Content)" />. My problem is when the XML() argument is not a very clean html string, XML fail miserably. How can I manage to roughly clean that string (in the template) or at least return the string not formated, instead of having an exception thrown.
> In my kid template I have this following line: <div > class="reviewitem" py:content="XML(review.Content)" />. > My problem is when the XML() argument is not a very clean html > string, XML fail miserably. > How can I manage to roughly clean that string (in the template) or at > least return the string not formated, instead of having an exception > thrown.
> You could put an ajax call on your page, retrieve that string through > an seprate request and then render your string using innerHTML from > javascript.
um.. that sounds like a terribly bad idea. a) it produces a webpage where the content is only availble with javascript and a AJAX-enabled browser. b) What sense does it make to use kid and then try to circumvent one of kid's main features, ensuring correctness of output?
> In my kid template I have this following line: <div > class="reviewitem" py:content="XML(review.Content)" />. > My problem is when the XML() argument is not a very clean html > string, XML fail miserably. > How can I manage to roughly clean that string (in the template) or at > least return the string not formated, instead of having an exception > thrown.
I think the only way apart from horribly circumventing kid is to have clean (X)HTML markup. I'm currently using a validator like this to validate XHTML markup..
s = template.serialize( output = "xml") return s[s.index("<html>")+6:-7]
It uses a temporary template to check the XHTML code for correctness, feeds errors back as validation errors and extracts the cleaned-up XHTML markup from the serialized output.
> You could put an ajax call on your page, retrieve that string through > an seprate request and then render your string using innerHTML from > javascript.
> But if the HTML isn't valid, you may have trouble rendering it no > matter what you do.
>> In my kid template I have this following line: <div >> class="reviewitem" py:content="XML(review.Content)" />. >> My problem is when the XML() argument is not a very clean html >> string, XML fail miserably. >> How can I manage to roughly clean that string (in the template) or at >> least return the string not formated, instead of having an exception >> thrown.
> Sorry, I can't use AJAX. I know AJAX is very fashionable right now > but it is not an option for this page. Also I think I would have the > same problem.
My suggestion was a bit tongue in cheek ;) It's the only way I know of to 100% avoid KID while using KID. And while you can get around Kid's validation that way, I don't particularly think it's a good idea either. But I thought I'd throw it out there in case you were looking for an ugly hack.
What I should have mentioned is that an easier way to get around KID in a situation like this is not to use KID at all. You can use Cheetah instead, and get around KID's validity requirement. Cheetah shouldn't care a bit about how broken your HTML is.
Automatic HTML repair sounds like it would be nice, and perhaps it's possible for some subset of HTML errors, but I doubt it's really feasible unless your HTML is already almost right, and is broken an easy to detect way. It seems like your best choice is to go to the source, and see if you can fix that.
I agree. I never said it was good, and I even said that it probably wouldn't work! But it's the only ugly hack I could think of to get done what Fred was asking for.
The right answer is exactly what you say. Don't use KID when you want to have invalid output. The right thing to do is to create valid output, but if that's not possible the second best thing is to use Cheetah, or one of the other available templates with TurboGears plugins that doesn't care about validity.
> In my kid template I have this following line: <div > class="reviewitem" py:content="XML(review.Content)" />. > My problem is when the XML() argument is not a very clean html > string, XML fail miserably.
why not make that string valid xhtml? XML is evil inside kid and should be avoid
How can I manage to roughly clean that string (in the template) or at
> least return the string not formated, instead of having an exception > thrown.
is that data coming from the db or a user? why not clean it up at insertion time?
> On 6/11/06, Fred C <bsdh...@gmail.com> wrote: >> Sorry, I can't use AJAX. I know AJAX is very fashionable right now >> but it is not an option for this page. Also I think I would have the >> same problem.
> My suggestion was a bit tongue in cheek ;) It's the only way I know > of to 100% avoid KID while using KID. And while you can get around > Kid's validation that way, I don't particularly think it's a good idea > either. But I thought I'd throw it out there in case you were > looking for an ugly hack.
> What I should have mentioned is that an easier way to get around KID > in a situation like this is not to use KID at all. You can use > Cheetah instead, and get around KID's validity requirement. Cheetah > shouldn't care a bit about how broken your HTML is.
> Automatic HTML repair sounds like it would be nice, and perhaps it's > possible for some subset of HTML errors, but I doubt it's really > feasible unless your HTML is already almost right, and is broken an > easy to detect way. It seems like your best choice is to go to the > source, and see if you can fix that.
I think you are right and I am going to use Cheetah instead of kid. I like kid and I like the fact that it forces you to write clean code, but it can be a pain when you get part of your html content from a third party with a lot of small errors.
I have try to cleanup this code with ElementTidy, but this tool is not design to clean up a single string. It did not gave me the result expected. For fixing the source this is impossible, the only thing I can do with the source is read it. And I don't think the people who are producing that source gonna start closing the </p> , </li> or other tags who are not really affecting the presentation on their browsers.
> In my kid template I have this following line: <div > class="reviewitem" py:content="XML(review.Content)" />. > My problem is when the XML() argument is not a very clean html > string, XML fail miserably.
> why not make that string valid xhtml? XML is evil inside kid and > should be avoid
> How can I manage to roughly clean that string (in the template) or at > least return the string not formated, instead of having an exception > thrown.
> is that data coming from the db or a user? why not clean it up at > insertion time?
Just because this data is coming from a database from a third party and they don't feel the need to produce a clean html since it is displayed well in their browsers.
> I think you are right and I am going to use Cheetah instead of kid. I > like kid and I like the fact that it forces you to write clean code, > but it can be a pain when you get part of your html content from a > third party with a lot of small errors.
Not to mention when it mangles your code by putting spaces between images when you don't want them. How does one change templates? I think I'm more interested in Myghty.
Mike -- Michael P. Soulier <msoul...@digitaltorque.ca> "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." --Albert Einstein
> In my kid template I have this following line: <div > class="reviewitem" py:content="XML(review.Content)" />. > My problem is when the XML() argument is not a very clean html > string, XML fail miserably. > How can I manage to roughly clean that string (in the template) or at > least return the string not formated, instead of having an exception > thrown.