Namespace not honered in find_all

Bug #1655332 reported by delijati
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Beautiful Soup
Fix Released
Undecided
Unassigned

Bug Description

Namespace are not honored in find_all when using "xml":

Example:

import bs4

doc = """<?xml version="1.0" encoding="utf-8"?>
<Foo xmlns="http://bla.com/foo-1.0"
    xmlns:mashup="http://bla.com/mashup-1.0"
    xmlns:uxc="http://bla.com/uxc-1.0">
    <uxc:InPorts>
        <uxc:InPort name="COD_DUNS_NUMBER_Info_In">
            <uxc:Parameter name="CompanyName">
            </uxc:Parameter>
            <uxc:Parameter name="EntityId">
            </uxc:Parameter>
        </uxc:InPort>
    <uxc:InPorts>
    <mashup:Request>
        <mashup:Parameter constant="far2" context="query" name="bloo"/>
    </mashup:Request>
</Foo>
"""

dom = bs4.BeautifulSoup(doc, "lxml-xml")
# How to search only for mashup elements?
# find_all('mashup:Parameter') does not work
elements = dom.find_all("Parameter")
print(elements)
print([x.prefix for x in elements])

Revision history for this message
delijati (delijati) wrote :

Found a way:

params = dom.find_all(
    lambda tag: (
        tag.name == "Parameter" and
        tag.prefix == "mashup")
)

Revision history for this message
Leonard Richardson (leonardr) wrote :

Feature added in revision 442.

Changed in beautifulsoup:
status: New → Fix Committed
Changed in beautifulsoup:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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