xml-wrangler icon indicating copy to clipboard operation
xml-wrangler copied to clipboard

Add the ability to chain reader methods on `Element` class

Open Sammyjo20 opened this issue 2 years ago • 2 comments

It would be really cool if you could use the search/reader methods on the base Element class that comes from the reader.

$reader = XmlReader::fromString(...);

$element = $reader->element('food.2')->sole();

$element->element('name')->sole();
$element->value('name')->sole();
$element->xpathElement('//name')->sole();
$element->xpathValue('//name')->sole();

I've started implementing this as a proof-of-concept.

Sammyjo20 avatar Nov 15 '23 20:11 Sammyjo20

Are there currently any plans to update and merge the branch with this feature?

jtbrown2-bsu avatar May 30 '25 21:05 jtbrown2-bsu

In my use case this is essential to efficiently handle large files (15-50k lines). Part of the difficulty I am having is that I don't see a way to chain queries. For example, I would like to get elements based on tags and attributes, then I would like to reuse that result for multiple different queries to get specific content within that tag.

Am I just missing how this is supposed to work? I couldn't see a way to chain query results in the Query model.

mikebronner avatar Jun 26 '25 01:06 mikebronner