%% Write Table Containing Namespace Prefixes to XML File
% Write a table containing namespace prefixes in the variable names to an XML file.
% Create a table of data.

LastName = {'Sanchez';'Johnson';'Lee';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
T = table(LastName,Age,Height,'VariableNames',{'myPrefix1:LastName','myPrefix2:Age','myPrefix3:Height'})

% Write table T to an XML file.
% If a table variable name contains a colon character, then writetable interprets the characters preceding the ":" as a namespace prefix, and creates an associated namespace URL in the output XML file. To ensure that the node names in the output file are the same as the input variable names, assign a prefix to the node name using the RowNodeName name-value argument. For example, specify the value of RowNodeName as 'myPrefix4:Patient' to assign the prefix myPrefix4 to the Patient node in the output file.

writetable(T,'Patients.xml','RowNodeName','myPrefix4:Patient')

% Display the contents of the output XML file. All element nodes have a namespace prefix and associated URL.

type Patients.xml

% Copyright 2020 The MathWorks, Inc.