RazrFalcon / roxmltree

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

Attribute value position/range no longer available since v0.16 #99

Closed MoSal closed 1 year ago

MoSal commented 1 year ago

Minimal example from versions 0.15 and smaller:

struct Foo<'input> {
    t2: &'input str,
}

// works with roxmltree v0.15
fn get_foo<'input>(xml_str: &'input str) -> Foo<'input> {
    let xml = roxmltree::Document::parse(xml_str).unwrap();
    let root_node = xml.root_element();
    for attr in root_node.attributes() {
        if attr.name() == "t2" {
            return Foo { t2: &xml_str[attr.value_range()]}
        }
    }
    unreachable!()
}

Attribute::value_range removal is the issue here.

This relates to #88. But the proposed solution requires using StringStorage, if I'm not mistaken, which is not ideal.

My use-case for example is a deriving/deserialisation framework. All users will have to use StringStorage fields if they want zero-copy (unless a layer of indirection like rkyv::Archive is added, which for me would be an overkill).

RazrFalcon commented 1 year ago

But the proposed solution requires using StringStorage, if I'm not mistaken, which is not ideal.

Are you trying to simply slice the input string instead? This is incorrect.

MoSal commented 1 year ago

But the proposed solution requires using StringStorage, if I'm not mistaken, which is not ideal.

Are you trying to simply slice the input string instead? This is incorrect.

Yes. I just took a deeper look (the normalization code) and I understand the reasoning behind the API now.