ixml parser: a whitespace-only value is content, not formatting - #1226
Merged
Merged
Conversation
The parse loop skips the whitespace between two tags, which is right for the
indentation of a pretty-printed document but wrong when that whitespace is
everything an element contains: `<FIELD> </FIELD>` carries a blank and
`<FIELD>{LF}</FIELD>` a line break, and both came back as an empty string.
Through `CALL TRANSFORMATION id` and the parse back that is a lost value: a
string that holds nothing but blanks or a line break is initial afterwards.
The skip now keeps the whitespace when it stands directly between a start tag
and its own end tag, and drops it everywhere else, so indentation is read as
before - the first child of a pretty-printed element is still the element.
Tests: the asXML roundtrip of a blank-only and of a newline-only value, the
parser keeping the blank in `<item> </item>`, and indentation still not
turning into a #text node.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKSWLpid4QLV6XWAoPixbb
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.
What is wrong
if_ixml_parser~parseskips the whitespace between two tags at the end ofevery iteration,
src/ixml/cl_ixml.clas.locals_imp.abap:That is right for the indentation of a pretty-printed document, but it also
fires when the whitespace is everything an element contains.
<FIELD> </FIELD>and
<FIELD>+ LF +</FIELD>have no text node afterwards, so the value isgone.
Through
CALL TRANSFORMATION idand the parse back this is a lost value — astring holding nothing but blanks or a line break comes back initial:
The change
The skip now keeps the whitespace when it stands directly between a start tag
and its own end tag, and drops it everywhere else:
lv_in_elementis set where the tag is read: true after a start tag that isnot self-closing, false after the prolog, a close tag, a self-closing tag and
a value. Whitespace before a child element (
<a>+ LF +<b/>) or betweentwo siblings stays formatting and is dropped as before — the first child of a
pretty-printed element is still the element, not a
#textnode.One behaviour does change on purpose: an element that contains only
whitespace now has a text node,
<a>+ LF +</a>reads as a line break.That is what a system returns, and it is the same value the document was
written from.
Tests
kernel_call_transformation:blank_only_roundtripandnewline_only_roundtrip— a value of one blank / one LF throughCALL TRANSFORMATION idand backcl_ixml:parse_blank_only_value—<item> </item>keeps the blankcl_ixml:parse_indented_children— indentation still does not become a#textnodenpm testis green:abaplint: 0 issue(s) found, 735 file(s) analyzed, andthe full unit run passes.
Why it matters downstream
abap2UI5 serializes the whole app state per request with
CALL TRANSFORMATION idinto the draft and parses it back on the next one(
z2ui5_cl_ui5_util_context=>xml_stringify/xml_parse), so any value theroundtrip drops is a value the app loses. After #1225 a line break inside a
value survives; a value that is a line break, or a blank, still does not.