%% Get Type of Element in Parsed XML Document
% This example saves post-schema-validation information (PSVI) in the elements of a parsed XML document and then uses a matlab.io.xml.dom.TypeInfo object to get the type of one of the elements.
% The file checkingaccount.xml contains the markup for a bank account and specifies the schema checkingaccount.xsd.

type checkingaccount.xml

% The schema specifies that an account element has an id, name, and balance element. The id and name elements must contain a string and the balance element must contain a decimal number.

type checkingaccount.xsd

% Configure a parser to validate the XML against the schema and save the post-schema-validation information in the parsed elements. Read the XML file into a DOM document using the parser.

import matlab.io.xml.dom.*

parser = Parser();
parser.Configuration.Schema = true;
parser.Configuration.Validate = true;
parser.Configuration.HasPSVI = true;
doc = parseFile(parser,"checkingaccount.xml");

% Find the balance element in the document.

nodelistObj = getElementsByTagName(doc,"balance");
balanceElementObj = node(nodelistObj,1);

% Return the type information for the balance element as a matlab.io.xml.dom.TypeInfo object.

typeInfoObj = getSchemaTypeInfo(balanceElementObj);

% To get the name of the type, call the getTypeName method.

getTypeName(typeInfoObj)

%
% Copyright 2020 The MathWorks, Inc.