简体   繁体   中英

lxml namespaces defined multiple times

I am switching from python xml to lxml. I faced that lxml has rather strict policy towards namespaces.

I want to produce a xml with multiple redundant xmlns:ns0 namespace declaration. However, lxml strips this namespaces from child Elements.

How can I define redundant namespaces via lxml?

<?xml version="1.0" ?>
<env:Envelope xmlns:env="some URI" xmlns:ns0="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance">
    <env:Body>
        <ns0:getLabelResponseElement>
            <ns0:result>
                <ns1:statusMessage xmlns:ns0="http://www.w3.org/2001/XMLSchema"></ns1:statusMessage>
            </ns0:result>
        </ns0:getLabelResponseElement>
    </env:Body>
</env:Envelope>

Based on my research, lxml doesn't allow to add redundant namespace declaration in child Elements since this violates XML standards. So, even if you explicitly redeclare namespace in child element lxml wouldn't add it in final XML.
Unlike lxml, python-xml library allows redundant xml namespace declaration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM