Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing ability to get all attributes including namespace #104

Open
faassen opened this issue Nov 29, 2022 · 3 comments
Open

missing ability to get all attributes including namespace #104

faassen opened this issue Nov 29, 2022 · 3 comments

Comments

@faassen
Copy link

faassen commented Nov 29, 2022

Consider this:

<foo xmlns:ns="http://example.com" bar="BAR" ns:bar="NS BAR" />

How can I find out that attributes bar and ns:bar both exist?

The Node API offers get_attributes which returns a HashMap with all attributes, but this loses namespace information and I only get bar once.

I can access individual attributes by namespace using get_attribute_ns, but I have no way to find out which attributes exist in the first place. I would expect something like get_attributes_ns which returns a vec of Node (of type AttributeNode, like what is returned by get_attribute_node) in order to find this out. Or alternatively a get_attribute_names_ns which gives a vec of attribute name, attribute namespace tuples.

Am I missing something or this is something the API doesn't implement yet?

@dginev
Copy link
Member

dginev commented Nov 29, 2022

Am I missing something or this is something the API doesn't implement yet?

I think the namespace support is lacking in the current wrapper, so this would need a new method, likely get_attributes_ns, as you suggest.

@anwaralameddin
Copy link
Contributor

I needed the same and have implemented it with the signature

pub fn get_properties_ns(&self) -> HashMap<(Option<Namespace>, String), String>

For my use case, I have implemented PartialEq and Hash for Namespace using the methods get_prefix and get_href rather than ns_ptr.

Shall I create a pull request? Or do you have a different signature or implementation in mind?

@dginev
Copy link
Member

dginev commented Feb 23, 2024

@anwaralameddin your suggestion sounds reasonable to me. I'm happy to accept such a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants