Repository navigation
xmerl: export callbacks stripping comments. #5697
Copy link
Copy link
Closed
Labels
bugIssue is reported as a bugIssue is reported as a bughelp wantedIssue not worked on by OTP; help wanted from the communityIssue not worked on by OTP; help wanted from the communitypriority:lowteam:PSAssigned to OTP team PSAssigned to OTP team PS
Description
Describe the bug
The documentation (https://www.erlang.org/doc/man/xmerl.html) claims that the various export methods will export XML content including xmlComment elements.
When the content is exported the xmlComment elements are not retained.
To Reproduce
Simple xml file called s1.xml.
<?xml version = "1.0" encoding = "UTF-8" ?>
<!--TOP COMMENT-->
<top>
<!--ELE TOP COMMENT-->
<ele>SOME TEXT</ele>
<!--ELE BOTTOM COMMENT-->
</top>
<!--BOTTOM COMMENT-->
Erl console:
> erl
Erlang/OTP 24 [erts-12.1] [source] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [jit]
Eshell V12.1 (abort with ^G)
1> {ParseResult,Misc}=xmerl_scan:file("s1.xml").
{{xmlElement,top,top,[],
{xmlNamespace,[],[]},
[],2,[],
[{xmlText,[{top,2}],1,[],"\n ",text},
{xmlComment,[{top,2}],2,[],"ELE TOP COMMENT"},
{xmlElement,ele,ele,[],
{xmlNamespace,[],[]},
[{top,2}],
3,[],
[{xmlText,[{ele,3},{top,2}],1,[],"SOME TEXT",text}],
[],".",undeclared},
{xmlText,[{top,2}],4,[],"\n ",text},
{xmlComment,[{top,2}],5,[],"ELE BOTTOM COMMENT"}],
[],".",undeclared},
[]}
2> xmerl:export_simple([ParseResult],xmerl_xml).
["<?xml version=\"1.0\"?>",
[[["<","top",">"],
["\n ",
[["<","ele",">"],["SOME TEXT"],["</","ele",">"]],
"\n "],
["</","top",">"]]]]
Expected behavior
XML comments if present would be retained in the exported list.
Affected versions
24 (only version tested)
Additional context
Sorry, I'm have only vague familiarity with Erlang and I may be missing a nuance of the documentation, but this took us by surprise. I briefly tested a handful of the other options e.g. SGML, text, HTML and the same issue is present. The same issue is also present in export/2.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugIssue is reported as a bugIssue is reported as a bughelp wantedIssue not worked on by OTP; help wanted from the communityIssue not worked on by OTP; help wanted from the communitypriority:lowteam:PSAssigned to OTP team PSAssigned to OTP team PS
Activity
xmerl: Fix exporting XML comments
fix 5697: xmerl: Fix exporting XML comments
fix erlang#5697: xmerl: Fix exporting XML comments
Fix erlang#5697: xmerl: Fix exporting XML comments
Fix erlang#5697: xmerl: Fix exporting XML comments
xmerl: Fix exporting XML comments
xmerl: Fix exporting XML comments
Merge branch 'lars/xmerl/export-comments/GH-5697/PR-9796/OTP-19757' i…
lthor commentedon Sep 3, 2025
The fix made by ptome is merged and will be released in OTP 28.1
Ignore comments when parsing elements