最近在做project的时候 需要处理大量的XML,发现不仅省事,而且效率极高。
下面是我在CSDN上发现一个兄弟自己写的用matlab写xml的代码。
于是决定取百家之长,特此转载,希望造福一方啊
复制代码
生产XML文件如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65tempname = '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);
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21<? 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内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复