roxmltree icon indicating copy to clipboard operation
roxmltree copied to clipboard

Expose byte range(s) for attributes?

Open Jayonas opened this issue 5 months ago • 2 comments

I'm evaluating XML libraries for use on a project, and one thing that I'm looking for is the ability to get the byte ranges where various XML items came from in the original string/document, for use in error reporting. I found Node.range(), which is exactly what I'm looking for. However, attributes aren't Nodes so they don't benefit from this API. I found Attribute.position(), but it only provides the first byte rather than a range. Would you consider adding a range() method to Attribute? Or does something like that already exist and I missed it?

Even better -- would you consider adding separate ranges for an attribute's name and value? It would be nice to be able to pinpoint one or the other in different kinds of error messages. E.g. an "invalid attribute" error could pinpoint the name, whereas an "invalid value" error could pinpoint the value. I don't personally care very much whether the name's range includes its prefix (if any) or not, but I realize that's a thing that would need to be considered.

Another library that I've looked at is your xmlparser, which is far and away the best I've seen in terms of pinpointing the ranges of various items, not just separate prefix/name/value ranges for attributes, but even separate name/prefix for elements, separate full/contents-only ranges for comments and CDATA, and so forth. Though as you point out in its documentation, that library is very low-level and therefore very limited in actual XML processing and validation capabilities. I noticed that you recently went so far as to deprecate xmlparser in favor of simply merging it into this roxmltree library. For anyone that has been using xmlparser and the extra range information it provides, they might find it easier to transition to this library if it also made that extra information available. The main hang up for me is attribute ranges, but I would also applaud exposing subranges of various types of Nodes as well.

Jayonas avatar Jan 16 '24 18:01 Jayonas