%% Select Variables that Contain Different Number of Rows
% Select variables that contain a different number of rows in the output table.
% Create XML import options for an XML file. Specify the node that readtable selects as the rows of the output table using RowSelector and the row names using RowNamesSelector. Use VariableSelectors to select the variables to import.

opts1 = xmlImportOptions("RowSelector","//Student","RowNamesSelector","//@FirstName", ... 
    "VariableSelectors",["//Major" "//Minor"],"NumVariables",2,"VariableNames",["Major" "Minor"]);

% Use readtable along with the options object to import the specified variable.

T1 = readtable("students.xml",opts1)

% If you do not specify a value for RowSelector, the readtable function does not preserve the association between variables values and their corresponding table rows.

opts2 = xmlImportOptions("VariableSelectors",["//Major","//Minor"],"RowNamesSelector","//@FirstName", ...
    "NumVariables",2,"VariableNames",["Major","Minor"]);
T2 = readtable("students.xml",opts2)

% Copyright 2020 The MathWorks, Inc.