%% Format XML Output
% Write an XML document to a file and format the XML output so that it is indented and readable.
% Create an XML document as a matlab.io.xml.dom.Document object.

import matlab.io.xml.dom.*
docNode = Document("root_element");
docRootNode = getDocumentElement(docNode);
weekdays = ["Mon" "Tue" "Wed" "Thu" "Fri"];
weekdaysElement = createElement(docNode,"weekdays");
for i=1:5
    dayElement = createElement(docNode,"day");
    appendChild(dayElement,createTextNode(docNode,weekdays(i)));
    appendChild(weekdaysElement,dayElement);
end
appendChild(docRootNode,weekdaysElement);

% Create a writer to serialize the XML document.

xmlFileName = "weekdays.xml";
writer = matlab.io.xml.dom.DOMWriter;

% Specify pretty-print formatting.

writer.Configuration.FormatPrettyPrint = true;
writeToFile(writer,docNode,xmlFileName);

% View the formatted file.

type(xmlFileName);

%
% Copyright 2020 The MathWorks, Inc.