%% Create XML Elements and Text Nodes
% This example creates matlab.io.xml.dom.Element and matlab.io.xml.dom.Text objects to represent XML markup for weekdays.
% Import the matlab.io.xml.dom package so that you do not have to use long, fully qualified class names.

import matlab.io.xml.dom.*

% Create a document and the root element weekdays.

doc = Document("weekdays");
weekdaysElement = getDocumentElement(doc);

% Create a string array of the text for each weekday.

weekdays = ["Mon" "Tue" "Wed" "Thu" "Fri"];

% For each weekday, create an Element object for the day element and a Text object for the day text. Append the Text object to the day element and the day element to the weekdays element.

for i=1:5
    dayElement = createElement(doc,"day");
    appendChild(dayElement,createTextNode(doc,weekdays(i)));
    appendChild(weekdaysElement,dayElement);
end

% Write the XML to a file.

xmlFileName = "weekdays.xml";
writer = matlab.io.xml.dom.DOMWriter;
writeToFile(writer,doc,xmlFileName);

%
% Copyright 2020 The MathWorks, Inc.