Extra namespace attrubutes are added when writing with xmlfile

Bug #2034281 reported by Антон Белонович
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Confirmed
Low
Unassigned

Bug Description

When generating an XML file using streamed xmlfile, it adds extra namespace declarations:

<root xmlns:g="http://base.google.com/ns/1.0" version="2.0">
    <items>
        <item>
            <g:id xmlns:g="http://base.google.com/ns/1.0">1</g:id>
        </item>
        <item>
            <g:id xmlns:g="http://base.google.com/ns/1.0">2</g:id>
        </item>
        <item>
            <g:id xmlns:g="http://base.google.com/ns/1.0">3</g:id>
        </item>
        <item>
            <g:id xmlns:g="http://base.google.com/ns/1.0">4</g:id>
        </item>
        <item>
            <g:id xmlns:g="http://base.google.com/ns/1.0">5</g:id>
        </item>
    </items>
</root>

I expect xmlfile to just add element prefix, without repeating the "xmlns:g" attribute for each element, as namespace is already defined in the "root" element.

Expected output:

<root xmlns:g="http://base.google.com/ns/1.0" version="2.0">
    <items>
        <item>
            <g:id>1</g:id>
        </item>
        <item>
            <g:id>2</g:id>
        </item>
        <item>
            <g:id>3</g:id>
        </item>
        <item>
            <g:id>4</g:id>
        </item>
        <item>
            <g:id>5</g:id>
        </item>
    </items>
</root>

I attached a file with the sample script.

Python : sys.version_info(major=3, minor=11, micro=4, releaselevel='final', serial=0)
lxml.etree : (4, 9, 3, 0)
libxml used : (2, 10, 3)
libxml compiled : (2, 10, 3)
libxslt used : (1, 1, 38)
libxslt compiled : (1, 1, 38)

Revision history for this message
Антон Белонович (tralick) wrote :
scoder (scoder)
Changed in lxml:
importance: Undecided → Low
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.