您的位置:首页 > 编程语言 > MATLAB

matlab生成xml文件代码示例

2016-07-26 14:31 561 查看
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文件如下:

[html] view
plain copy

 <? 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 

  -->  

原文链接:地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: