Skip to content

Detecting newly introduced namespace attributes at individual element level? #48

@drott

Description

@drott

Hi, big thanks for maintaining this useful, ergonomic library.

For a specific StartElement event in the tree, I would like to find out if this element introduces any new namespaces.

<library xmlns:book="http://www.example.com/books">
    <book:title>The Great Novel</book:title>
    <book:author>John Doe</book:author>
    
    <review xmlns:feedback="http://www.example.com/feedback"> <feedback:rating>5 stars</feedback:rating>
        <feedback:comment>Excellent read.</feedback:comment>
     </review>
    
    <book:isbn>1234567890</book:isbn>
</library>

When I get the StartElement event for <review> how can I tell that xmlns:feedback is new here in the namespaces stack? Do I need to keep track of the previous BTreeMaps from the previous StartElement events and compare them to see which is new? Or is there a way I can tell which namespace was most recently introduced?

My understanding is that the namespace field of the StartElement event aggregates all namespaces encountered so far and reports those for every child element, independent of whether they are added on the current element or whether they were accumulated in parent elements.

Background: In a parser that converts the document to an internal structure, for example a DOM structure, without this sort of functionality I think I would otherwise be unable to reproduce the original document structure. Because I cannot tell directly from the API where a namespace was introduced, or can I?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions