You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With 2.12, Jackson can parse xml iwith multiple repeated elements into a tree (ignore duplicate feature). This make it possible to parse, but create challenge with extracting data.
the solution result in document structure that some times will have an array and sometimes a scalar, depending on if the element exists one time or multiple time.
Wanted to suggest borrowing a feature from Perl XML::simple, which make it possible to specify list of tags with the “forceArray” flag [https://metacpan.org/pod/XML::Simple#ForceArray-=%3E-%5B-names-%5D-%23-in-important]
From my experience, this approach make it significantly easier to tree parsing most documents with repeated attributes.
With this feature, the developer is can safely access the nodes that are associated with those tags using the array notation.
as a further improvement, allowing specification of tags in hierarchy will make it
Consider: <doc> <x> 1 </x> </doc>
That will parse to { x: q }
With the propose change, the above will parse into { x: [ 1 ] }
and
<doc> <x> 1 </x> <x> 2 </x> </doc>
That will parse to { x : [ 1, 2 ] }
In the first case the ‘x’ has a value. By specifying at attribute to the mapper forceArray = [ ‘x’], the mapper will always generate array for ‘x’ even if there is only one element, simplifying access to those array.
As an extension, if forceArray is provided and multiple elements are provided fir an element not in the forceArray list, this should be considered a parsing error.
The text was updated successfully, but these errors were encountered:
yairlenga
changed the title
Additional control over array fir xml parsing
Additional control over parsing of repeated elements
Oct 5, 2021
With 2.12, Jackson can parse xml iwith multiple repeated elements into a tree (ignore duplicate feature). This make it possible to parse, but create challenge with extracting data.
the solution result in document structure that some times will have an array and sometimes a scalar, depending on if the element exists one time or multiple time.
Wanted to suggest borrowing a feature from Perl XML::simple, which make it possible to specify list of tags with the “forceArray” flag [https://metacpan.org/pod/XML::Simple#ForceArray-=%3E-%5B-names-%5D-%23-in-important]
From my experience, this approach make it significantly easier to tree parsing most documents with repeated attributes.
With this feature, the developer is can safely access the nodes that are associated with those tags using the array notation.
as a further improvement, allowing specification of tags in hierarchy will make it
Consider:
<doc> <x> 1 </x> </doc>
That will parse to { x: q }
With the propose change, the above will parse into { x: [ 1 ] }
and
<doc> <x> 1 </x> <x> 2 </x> </doc>
That will parse to { x : [ 1, 2 ] }
In the first case the ‘x’ has a value. By specifying at attribute to the mapper forceArray = [ ‘x’], the mapper will always generate array for ‘x’ even if there is only one element, simplifying access to those array.
As an extension, if forceArray is provided and multiple elements are provided fir an element not in the forceArray list, this should be considered a parsing error.
The text was updated successfully, but these errors were encountered: