matlab写xml文件,写入 XML 文档对象模型节点

分两步编写 XML 文件。首先,创建一个包含 XML 数据的文档对象模型 (DOM) 节点。然后,将该 DOM 节点写入一个 XML 文件。最终的 XML 文件应该包含以下文本。

Upslope Area Toolbox

demFlow

facetFlow

flowMatrix

pixelFlow

首先,创建 DOM 节点对象和根元素,然后根据 XML 数据填充节点元素和节点属性。

docNode = com.mathworks.xml.XMLUtils.createDocument('toc');

确定根元素并设置 version 属性。

toc = docNode.getDocumentElement;

toc.setAttribute('version','2.0');

为产品页添加 tocitem 元素。此文件中的每个 tocitem 元素都有一个 target 属性和一个子文本节点。

product = docNode.createElement('tocitem');

product.setAttribute('target','upslope_product_page.html');

product.appendChild(docNode.createTextNode('Upslope Area Toolbox'));

toc.appendChild(product);

添加注释。

product.appendChild(docNode.createComment(' Functions '));

为每个函数添加一个 tocitem 元素,其中 target 为 function_help.html 形式。

functions = {'demFlow','facetFlow','flowMatrix','pixelFlow'};

for idx = 1:numel(functions)

curr_node = docNode.createElement('tocitem');

curr_file = [functions{idx} '_help.html'];

curr_node.setAttribute('target',curr_file);

% Child text is the function name.

curr_node.appendChild(docNode.createTextNode(functions{idx}));

product.appendChild(curr_node);

end

最后,将该 DOM 节点导出到名为 infoUAT.xml 的 XML 文件中,并使用 type 函数查看该文件。

xmlwrite('infoUAT.xml',docNode);

type('infoUAT.xml');

Upslope Area ToolboxdemFlow

facetFlow

flowMatrix

pixelFlow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值