XMLREAD Parse an XML document and return a Document Object Model node.
DOMNODE = XMLREAD(FILENAME) reads a URL or file name in the
string input argument FILENAME. The function returns DOMNODE,
a Document Object Model (DOM) node representing the parsed document.
The node can be manipulated by using standard DOM functions.
Note: A properly parsed document will display to the screen as
>> xDoc = xmlread(...)
xDoc =
[#document: null]
Example 1: All XML files have a single root element. Some XML
files declare a preferred schema file as an attribute of this element.
xDoc = xmlread(fullfile(matlabroot,'toolbox/matlab/general/info.xml'));
xRoot = xDoc.getDocumentElement;
schemaURL = char(xRoot.getAttribute('xsi:noNamespaceSchemaLocation'))
Example 2: Each info.xml file on the MATLAB path contains
several elements with a and element. This
script finds the callback that corresponds to the label 'Plot Tools'.
infoLabel = 'Plot Tools'; infoCbk = ''; itemFound = false;
xDoc = xmlread(fullfile(matlabroot,'toolbox/matlab/general/info.xml'));
% Find a deep list of all elements.
allListItems = xDoc.getElementsByTagName('listitem');
%Note that the item list index is zero-based.
for i=0:allListItems.getLength-1
thisListItem = allListItems.item(i);
childNode = thisListItem.getFirstChild;
while ~isempty(childNode)
%Filter out text, comments, and processing instructions.
if childNode.getNodeType == childNode.ELEMENT_NODE
%Assume that each element has a single org.w3c.dom.Text child
childText = char(childNode.getFirstChild.getData);
switch char(childNode.getTagName)
case 'label' ; itemFound = strcmp(childText,infoLabel);
case 'callback' ; infoCbk = childText;
end
end
childNode = childNode.getNextSibling;
end
if itemFound break; else infoCbk = ''; end
end
disp(sprintf('Item "%s" has a callback of "%s".',infoLabel,infoCbk))
See also xmlwrite, xslt.
Reference page in Help browser
doc xmlread
建议你多用下help,.