0

I'm trying to find a service, library, utility, whatever that converts XML to YAML and includes comments. It's easy to find a lot of XML to YAML converters, but I can't find one that includes XML comments in the YAML output. For example, using the XML input below:

<!-- This section has a comment -->
<CommentedElement>
    <ChildElement id="1" />
    <ChildElement id="2" />
</CommentedElement>

I want the YAML output to be:

# This section has a comment
CommentedElement: 
 ChildElement: 
  - 
   _id: 1
  - 
   _id: 2
Ray Dixon
  • 3
  • 3
  • You can try asking at [Software Recommendations](https://softwarerecs.stackexchange.com) but the main problem is that while XML defines comments as part of its structure, YAML only defines them as part of the representation and thus, most YAML implementations do not provide a way of generating YAML output with comments (since they are not part of the structure given to the representer). – flyx Jun 05 '20 at 21:11
  • Thanks, @flyx . The structure-only argument is a good reason to leave out comments from a converter. However, presentation or not, comments are part of both XML and YAML, so I am hoping that someone else has had a need to do this and can refer me to something already implemented. Thanks for the reference to [Software Recommendations](https://softwarerecs.stackexchange.com/). I [posted my question over there](https://softwarerecs.stackexchange.com/questions/74870/is-there-a-converter-that-converts-xml-to-yaml-and-includes-comments), as well, and I'll cross reference here if I get an answer. – Ray Dixon Jun 05 '20 at 21:47

1 Answers1

0

After looking around for a while I believe the answer to my question is 'No', as I can find no XML to YAML converters that include comments.

Ray Dixon
  • 3
  • 3
  • it's frustrating because it should be simple enough, but converters likely just load the xml using established parsers and then iterate over the parsed version which excludes comments – Switch386 Oct 13 '22 at 14:30