HTML / DOM
Bo M. Maryniuck
b.maryniuk at forbis.lt
Sat Mar 29 10:07:57 EST 2003
On Saturday 29 March 2003 11:38, Martin v. Löwis wrote:
> To find the A tag, do
> elem = d.getElementsByTagName("a")[0] #arbitrarily take the first A
> To read the attribute, do
> elem.getAttributeNS(None,'a')
Yes. This is exactly what I did. And this is exactly what does
not work -- returns me always an empty list.
I think 4Suite really has a bug like you mentioned:
>>> from xml.dom.ext.reader import HtmlLib as hl
>>> d = hl.FromHtml('<p> para text <a name="foo">bar</a></p><br>')
>>> d.getElementsByTagName("a")
<NodeList at 82b1274: []>
But:
>>> d = hl.FromHtml('<html><body><p>text <a name="foo">bar</a></p><br></body></html>')
>>> d.getElementsByTagName("a")
<NodeList at 831651c: [<Element Node at 83102ec: Name='A' with 1 attributes and 1 children>]>
Well, this trick (to find the attributes) is good when you want to generate a
Table Of Contents with XSLT. I currently work on a parser for OpenOffice.org documents
via Web for Zope and I found that GNOME libxslt does one thing:
---------------------------------------------
<xsl:variable name="Martin">Martin v. Löwis</xsl:variable>
<a>
<xsl:attribute name="href">#<xsl:value-of select="$Martin" /></xsl:attribute>
<xsl:text>Here!</xsl:text>
</a>
<xsl:apply-templates />
...
<a>
<xsl:attribute name="name"><xsl:value-of select="$Martin" /></xsl:attribute>
<xsl:text>Here!</xsl:text>
</a>
<xsl:apply-templates />
---------------------------------------------
Will provide a link:
<a href="#Martin%20v.%20L%F6wis">Here!</a>
...for the anchor:
<a name="Martin v. Löwis">Here!</a>
...and it will not work on <censored/> M$ IE all versions. So I desired to
patch HTML after, or XML before the parsing (depends from many circumstances).
Thank you much for help! I think it is solved problem.
--
Regards, Bogdan
Some people around here wouldn't recognize
subtlety if it hit them on the head.
More information about the Python-list
mailing list