feat: add toArray() and toObject() with namespace support#70
Open
guillaumedelre wants to merge 1 commit into
Open
feat: add toArray() and toObject() with namespace support#70guillaumedelre wants to merge 1 commit into
guillaumedelre wants to merge 1 commit into
Conversation
FluidXml::toArray() returns ['rootTag' => value] for the document. FluidContext::toArray() returns an array of ['tag' => value] entries for each selected node. Conversion rules: - Text-only element -> plain string value - Empty element -> null - Attributes -> '@name' keys - Text with siblings -> '@' key - CDATA content -> '@:cdata' key - Comment -> '@:comment' key - Repeated child tags -> indexed sub-arrays - Namespace decls -> '@xmlns' / '@xmlns:prefix' keys (only those introduced on the element, not inherited) The output mirrors the array syntax accepted by addChild(), enabling round-trip import/export. FluidXml::toObject() and FluidContext::toObject() return the same structure as stdClass instead of arrays, which integrates more naturally with JSON workflows and property-access code. Associative arrays become stdClass objects; indexed arrays (repeated siblings) remain PHP arrays. Namespace declarations are detected via the XPath namespace::* axis, comparing in-scope namespaces with the parent element to emit only the declarations local to each node. Closes downforcetech#28 Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
Author
|
Hey @daniele-orlando, this PR fixes #28 — happy to adjust if anything looks off. |
Author
|
Hey @daniele-orlando, just checking in on this. Happy to adjust the approach if needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FluidXml::toArray() returns ['rootTag' => value] for the document. FluidContext::toArray() returns an array of ['tag' => value] entries for each selected node.
Conversion rules:
introduced on the element, not inherited)
The output mirrors the array syntax accepted by addChild(), enabling round-trip import/export.
FluidXml::toObject() and FluidContext::toObject() return the same structure as stdClass instead of arrays, which integrates more naturally with JSON workflows and property-access code. Associative arrays become stdClass objects; indexed arrays (repeated siblings) remain PHP arrays.
Namespace declarations are detected via the XPath namespace::* axis, comparing in-scope namespaces with the parent element to emit only the declarations local to each node.
Closes #28