Skip to content

Conversation

aufi
Copy link
Contributor

@aufi aufi commented Aug 21, 2025

In my use-case it was needed to run xpath query on the XML and be able to show relevant context of the match. The match could be just empty element with or without attributes, potentialy spanning over multiple lines, so some kind of grep of the source file with matched Node content was very fragile.

In order to provide reliable line numbers for matched nodes, the parser needed to be updated. As an addition to existing methods for parsing, ParseWithLineNumbers and ParseWithLineNumbersWithOptions were added and their output provides Node with populated line numbers. Original behaviour should not be changed, just got line numbers with default 0.

It would be great get this feature in, but I'm flexible on how to do that. I'm looking forward to feedback on reviews, thanks!

@zhengchun
Copy link
Contributor

Hello, @aufi , Thank you for your suggestion. To simplify the public API and reduce the number of methods, we could add a WithLineNumbers bool field to the ParserOptions struct. This allows us to consolidate the functionality of ParseWithLineNumbers and ParseWithLineNumbersAndOptions into the standard ParseWithOptions method and remove ParseWithLineNumbers and ParseWithLineNumbersAndOptions

Signed-off-by: Marek Aufart <maufart@redhat.com>
@zhengchun zhengchun merged commit deb27cf into antchfx:master Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants