%% Get Names and Values of Attributes of an Element
% This example finds and displays the names and values of the attributes of an element.
% Read an XML string into a matlab.io.xml.dom.Document object.

import matlab.io.xml.dom.*
doc = parseString(Parser,'<para Bold="on" Color="red">Hello</para>');

% Get the elements named para.

paralist = getElementsByTagName(doc,'para');
m = getLength(paralist)-1;
s = '';

% For every para element, get the attribute names and values and save them in the character vector s.

for i = 0:m
    para = item(paralist,i);
    attrlist = getAttributes(para);
    n = getLength(attrlist)-1;
    for j=0:n
        attr = item(attrlist,j);
        s = [s sprintf('%s = %s\n',getNodeName(attr),getNodeValue(attr))];
    end
end

% Display the attribute names and values stored in s.

disp(s);

%
% Copyright 2020 The MathWorks, Inc.