%% Evaluate a Compiled XPath Expression
% This examples compiles an XPath expression and passes the compiled expression to an XPath expression evaluator.
% The example uses the file music.xml, which contains this XML markup:
% <MusicalEnsemble>
% 	<Ensemble>
% 		<Music>Jazz</Music>
%             <BandName>Kool Katz</BandName>
% 		<Instrumentation>
% 			<Instrument type="wind">Trumpet
%             </Instrument>
% 			<Instrument type="percussion">Piano
%                 <pianotype>concert grand</pianotype>
%             </Instrument>
% 			<Instrument type="percussion">Drums
%                 <drumkit>Bass drum</drumkit>
%                 <drumkit>Floor tom</drumkit>
%                 <drumkit>Snare drum</drumkit>
%                 <drumkit>Hi-hat</drumkit>
%                 <drumkit>Ride cymbal</drumkit>
%             </Instrument>
% 			<Instrument type="string">Bass
%                 <basstype>upright</basstype>
%             </Instrument>
% 		</Instrumentation>
% 	</Ensemble>
%     <Musicians>
%         <Name role="trumpeter">Miles</Name>
%         <Name role="vocalist">Roger</Name>
%         <Name role="pianist">Diana</Name>
%         <Name role="drummer">George</Name>
%         <Name role="bassist">John</Name>
%     </Musicians>
% </MusicalEnsemble>
% Compile the XPath expression //Instrument by calling the compileExpression method of a matlab.io.xml.xpath.Evaluator object.

import matlab.io.xml.xpath.*

evalObj = Evaluator();
compExpObj = compileExpression(evalObj,"//Instrument");

% Evaluate the compiled expression in the context of music.xml and return the resulting nodes as a vector of node objects.

xmlFilePath = "music.xml";
data = evaluate(evalObj,compExpObj,xmlFilePath,EvalResultType.NodeSet)

%
% Copyright 2020 The MathWorks, Inc.