HTML / DOM

Justin Ryan justin at gnubia.net
Sun Mar 30 00:19:05 CET 2003


If you can do what you need with XML, why not do that and use an XSLT
stylesheet to render as HTML?

On Fri, 2003-03-28 at 14:32, Bo M. Maryniuck wrote:
> Hello, all.
> 
> Can anybody drop me a real code how to work with DOM in _HTML_ which is even 
> not XHTML? I took a look over 4DOM but unfortunately documentation there is 
> too silly. :( Well, for example, I have a HTML string:
> 
> 	<p>Text here <a name="foo">bar</a></p>
> 
> Now, how to build a DOM from this chunk to do the following:
> 	1. Fetch somehow a "name" attribute from the "<A/>" tag
> 	2. Change it (not a "bar", but a "foo" value!)
> 	3. Push it back to the same place
> 	4. Return modified HTML back as string without doctype and so on.
> 
> Any ideas? I know how to work with XML, but HTML-stuff drives me crazy since 
> it does not XML. Yes, I've tried to RTFM and STFW, but now I gave up -- this 
> all does not work as I need.
> 
> What I need to do with it. I have a HTML's where I need to found all the tags 
> <a name="foo"> which contains Unicode data in the "name" attribute and 
> urllib.quote() it than return this HTML back. But how to do it with DOM in 
> HTML -- I have no idea, since this is not XML... :(
> 
> Thank you for any help and any *working* ideas and examples. :)
> 
> -- 
> Regards, Bogdan
> 
> If vegetarians eat vegetables, what do humanitarians eat?
> 






More information about the Python-list mailing list