Skip to content

xmerl: export callbacks stripping comments. #5697

Closed

Description

@os6sense

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.

Activity

  1. added
    help wantedIssue not worked on by OTP; help wanted from the community
    and removed
    stalledwaiting for input by the Erlang/OTP team
    on May 28, 2024
  2. added 4 commits that reference this issue on Mar 27, 2025
  3. added 2 commits that reference this issue on May 5, 2025
    88afca9
    4f21437
  4. lthor commented on Sep 3, 2025

    @lthor
    Contributor

    The fix made by ptome is merged and will be released in OTP 28.1

  5. added a commit that references this issue on Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bughelp wantedIssue not worked on by OTP; help wanted from the communitypriority:lowteam:PSAssigned to OTP team PS

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions