xml.etree and namespaces -- why?

Axy axy at declassed.art
Wed Oct 19 10:53:37 EDT 2022


I have no idea why, I used to remove namespaces, following the advice 
from stackoverflow:

https://stackoverflow.com/questions/4255277/lxml-etree-xmlparser-remove-unwanted-namespace

_ns_removal_xslt_transform = etree.XSLT(etree.fromstring('''
     <xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="xml" indent="no"/>

     <xsl:template match="/|comment()|processing-instruction()">
         <xsl:copy>
           <xsl:apply-templates/>
         </xsl:copy>
     </xsl:template>

     <xsl:template match="*">
         <xsl:element name="{local-name()}">
           <xsl:apply-templates select="@*|node()"/>
         </xsl:element>
     </xsl:template>

     <xsl:template match="@*">
         <xsl:attribute name="{local-name()}">
           <xsl:value-of select="."/>
         </xsl:attribute>
     </xsl:template>
     </xsl:stylesheet>
'''))

xml_doc = _ns_removal_xslt_transform(

     etree.fromstring(my_xml_data)

)


Later on, when I worked with SVG, I used BeautifulSoup.

Axy.


More information about the Python-list mailing list