概述
最近在做project的时候 需要处理大量的XML,发现不仅省事,而且效率极高。
下面是我在CSDN上发现一个兄弟自己写的用matlab写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 >
<!--
this is a comment
-->
下面是原创兄弟的链接,希望大家能尊重原创。
http://blog.csdn.net/minutes_seconds/article/details/6531096
最后
以上就是坚强大米为你收集整理的一个MATLAB 写xml 文件的例子的全部内容,希望文章能够帮你解决一个MATLAB 写xml 文件的例子所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复