matlab的xmlread,Matlab的xmlread函数怎么用?

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,.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值