RazrFalcon / roxmltree

Represent an XML document as a read-only tree.
Apache License 2.0
434 stars 37 forks source link

attribute() cannot find attributes with colon in names #104

Closed sayanb closed 1 year ago

sayanb commented 1 year ago

Example

<image xlink:href="tree.jpg" x="50">

Once a Node (let's call it image_node) has been obtained for this,

if let Some(url) = image_node.attribute("xlink:href") is not able to find the attribute xlink:href. However, if let Some(x) = image_node.attribute("x") is able to find the attribute x as expected.

adamreichold commented 1 year ago

This is because xlink:href is not the name of the attribute, xlink: is a namespace prefix. So you need to either expand the namespace behind the xlink prefix ask for that using image_node.attribute(("the-url-of-the-xlink-namespace", "href")) or if you do not care about the namespace, filter using image_node.attributes().find(|attr| attr.name() == "href").