matlab写xml文件,一个MATLAB 写xml 文件的例子 | 学步园

网上看了不少例子,但是真的能用的一个没有。 这里我写了一个比较详细的例子,里面包含了一些嵌套,在matab 2009上确实可用,生成的xml文件在当前文件夹,名字叫 myxml.xml

tempname = 'myxml';

docNode = com.mathworks.xml.XMLUtils.createDocument('obj')

docRootNode = docNode.getDocumentElement;

%docRootNode.setAttribute('attr_name','attr_value');

IDNode = docNode.createElement('ID');

IDNode.appendChild(docNode.createTextNode(sprintf('%i',5)));

docRootNode.appendChild(IDNode);

objNmNode = docNode.createElement('objNm');

objNmNode.appendChild(docNode.createTextNode(sprintf('plane####################1008')));

docRootNode.appendChild(objNmNode);

thisElement = docNode.createElement('FDs');

docRootNode.appendChild(thisElement);

dataNode = docNode.createElement('FD1');

dataNode.appendChild(docNode.createTextNode(sprintf('4 43 3 32 1 6 0 3 1 2   ')));

thisElement.appendChild(dataNode);

dataNode = docNode.createElement('FD2');

dataNode.appendChild(docNode.createTextNode(sprintf('4 43 3 32 1 6 0 3 1 2   ')));

thisElement.appendChild(dataNode);

dataNode = docNode.createElement('FD3');

dataNode.appendChild(docNode.createTextNode(sprintf('4 43 3 32 1 6 0 3 1 2   ')));

thisElement.appendChild(dataNode);

dataNode = docNode.createElement('FD4');

dataNode.appendChild(docNode.createTextNode(sprintf('4 43 3 32 1 6 0 3 1 2   ')));

thisElement.appendChild(dataNode);

thisElement = docNode.createElement('FD_Clusters');

docRootNode.appendChild(thisElement);

dataNode = docNode.createElement('FD_Clusters1');

dataNode.appendChild(docNode.createTextNode(sprintf('4 43 3 32 1 6 0 3 1 2   ')));

thisElement.appendChild(dataNode);

dataNode = docNode.createElement('FD_Clusters2');

dataNode.appendChild(docNode.createTextNode(sprintf('4 43 3 32 1 6 0 3 1 2   ')));

thisElement.appendChild(dataNode);

dataNode = docNode.createElement('FD_Clusters3');

dataNode.appendChild(docNode.createTextNode(sprintf('4 43 3 32 1 6 0 3 1 2   ')));

thisElement.appendChild(dataNode);

dataNode = docNode.createElement('FD_Clusters4');

dataNode.appendChild(docNode.createTextNode(sprintf('4 43 3 32 1 6 0 3 1 2   ')));

thisElement.appendChild(dataNode);

FD_histoNode = docNode.createElement('FD_histogram');

FD_histoNode.appendChild(docNode.createTextNode(sprintf('17 10 8 5 3 2 1 ')));

docRootNode.appendChild(FD_histoNode);

docNode.appendChild(docNode.createComment('this is a comment'));

xmlFileName = [tempname,'.xml'];

xmlwrite(xmlFileName,docNode);

type(xmlFileName);

生成的xml文件如下:

xml

version="1.0" encoding="utf-8"

?>

-

<

obj

>

<

ID

>

5

ID

>

<

objNm

>

plane####################1008

objNm

>

-

<

FDs

>

<

FD1

>

4 43 3 32 1 6 0 3 1 2

FD1

>

<

FD2

>

4 43 3 32 1 6 0 3 1 2

FD2

>

<

FD3

>

4 43 3 32 1 6 0 3 1 2

FD3

>

<

FD4

>

4 43 3 32 1 6 0 3 1 2

FD4

>

FDs

>

-

<

FD_Clusters

>

<

FD_Clusters1

>

4 43 3 32 1 6 0 3 1 2

FD_Clusters1

>

<

FD_Clusters2

>

4 43 3 32 1 6 0 3 1 2

FD_Clusters2

>

<

FD_Clusters3

>

4 43 3 32 1 6 0 3 1 2

FD_Clusters3

>

<

FD_Clusters4

>

4 43 3 32 1 6 0 3 1 2

FD_Clusters4

>

FD_Clusters

>

<

FD_histogram

>

17 10 8 5 3 2 1

FD_histogram

>

obj

>

-

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值