%% Write XML Document to File
% Write an XML document to a file using a matlab.io.xml.dom.DOMWriter object.
% 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;

% Save the XML document to a file.

writeToFile(writer,docNode,xmlFileName);

%
% Copyright 2020 The MathWorks, Inc.