%% Add an Attribute to an Element
% This example creates and adds a matlab.io.xml.dom.Attr object to a matlab.io.xml.dom.Element object by using the setAttribute method of the Element object.
% 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 with the root element para.

doc = Document("para");
para = getDocumentElement(doc);

% Add a Color attribute to the para element.

setAttribute(para,"Color","red");

% Add text to the para element.

textNode = createTextNode(doc,"Hello");
appendChild(para,textNode);

% Write the XML to a file.

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

%
% Copyright 2020 The MathWorks, Inc.