%% Mix XML Output With Other Text Output
% Use a matlab.io.xml.dom.FileWriter object with a matlab.io.xml.dom.DOMWriter object to mix serialized XML output with output from other text sources. This example wraps the XML output with text that marks the beginning and end of the XML.
% Create an XML document.

import matlab.io.xml.dom.*
docNode = Document("root_element");
docRootNode = getDocumentElement(docNode);
setAttribute(docRootNode,"attribute","attribute_value");
for i=1:20
    thisElement = createElement(docNode,"child_node");
    appendChild(thisElement,createTextNode(docNode,sprintf("%i",i)));
    appendChild(docRootNode,thisElement);
end
appendChild(docNode,createComment(docNode,"this is a comment"));

% Create a matlab.io.xml.dom.FileWriter object and use the write method to write text to a file.

fileWriter = FileWriter('mixed.txt');
write(fileWriter,"Start of XML content:"+newline);

% Create a matlab.io.xml.dom.DOMWriter object and call the write method to write the serialized XML to the same file.

write(DOMWriter,docNode,fileWriter);

% Write more text to the file.

write(fileWriter,newline+"End of XML content");

%
% Copyright 2020 The MathWorks, Inc.