Comments inside XML

  • 28
  • Locked
Implement the toXmlWithComment method, which should return an XML-string representation of the obj object. A comment should be added in the line before each tagName tag. The XML serialization of obj may contain CDATA sections with the specified tag. Don't add comments before them.
You can't complete this task, because you're not signed in.
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Justin Smith
Level 38 , Greenfield, USA, United States
18 October 2022, 11:38
This task addresses a really important issue, and the task itself doesn't make it clear that that's what it's doing. In previous lessons we have learned how to convert a class to XML data. We do this by annotating the class(es) we want to convert. However, what if we want to convert an unknown type of object? What if we want to convert an object that we don't have the access to annotate? This task is about how to convert an unknown object type to XML. It is a topic worthy of much discussion. Unfortunately, I have significant issue with how it's been introduced here: Stuff you need to use that you haven't been formally introduced to in other lessons: Document class (with methods normalizeDocument, getDocumentElement, createCDATASection, getElementsByTagName, createComment) Transformer class (with methods transform, setOutputProperty) TransformerFactory class (with method newInstance) OutputKeys enum DOMSource class StreamResult class Node class (with methods hasChildNodes, getChildNodes, getTextContent, setTextContent, getParentNode, appendChild, insertBefore) NodeList class (with methods getLength, item) Comment class (with method normalize) DocumentBuilderFactory class (with method setNamespaceAware, newDocumentBuilder) DocumentBuilder class (with method parse) I don't mind if they throw a method (or even a class) in a task that we haven't seen before, but this is several lessons' worth of new material. It's too much. I would have said, put this in a regular lesson, maybe even two.
Level 27 , London, United Kingdom
16 March 2021, 12:37
Check out