xmlwrite
XML 문서 객체 모델 노드 쓰기
설명
예제
XML 파일 만들기
우선 XML 데이터를 포함하는 DOM(문서 객체 모델) 노드를 만드는 것으로 XML 파일 쓰기를 시작하십시오. 그런 다음 DOM 노드를 XML 파일에 씁니다. 최종 XML 파일은 다음 텍스트를 포함해야 합니다.
<?xml version="1.0" encoding="utf-8"?>
<toc version="2.0">
<tocitem target="upslope_product_page.html">Upslope Area Toolbox<!-- Functions -->
<tocitem target="demFlow_help.html">demFlow</tocitem>
<tocitem target="facetFlow_help.html">facetFlow</tocitem>
<tocitem target="flowMatrix_help.html">flowMatrix</tocitem>
<tocitem target="pixelFlow_help.html">pixelFlow</tocitem>
</tocitem>
</toc>
먼저 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 노드를 XML 파일 infoUAT.xml
로 내보내고, type
함수를 사용하여 파일을 확인합니다.
xmlwrite('infoUAT.xml',docNode); type('infoUAT.xml');
DOM(문서 객체 모델) 노드를 직렬화된 텍스트로 가져오기
샘플 XML 파일에서 DOM 노드를 읽어 들이고 DOM 노드의 내용을 문자형 벡터로 가져옵니다.
샘플 XML 파일의 내용을 표시하고, 파일에서 DOM 노드를 가져옵니다.
sampleXMLfile = 'sample.xml';
type(sampleXMLfile)
DOMnode = xmlread(sampleXMLfile);
xmlwrite
를 사용하여 DOMnode
객체를 직렬화된 문자형 벡터로 반환합니다.
text = xmlwrite(DOMnode)
text = '<?xml version="1.0" encoding="utf-8"?> <productinfo> <matlabrelease>R2012a</matlabrelease> <name>Example Manager</name> <type>internal</type> <icon>ApplicationIcon.DEMOS</icon> <list> <listitem> <label>Example Manager</label> <callback>com.mathworks.xwidgets.ExampleManager.showViewer </callback> <icon>ApplicationIcon.DEMOS</icon> </listitem> </list> </productinfo>'
입력 인수
filename
— 파일 이름
문자형 벡터 | string형 스칼라
파일 이름으로, 로컬 파일의 이름 또는 URL을 포함하는 문자형 벡터 또는 string형 스칼라로 지정됩니다.
데이터형: char
| string
DOMnode
— DOM(문서 객체 모델) 노드
DOM 노드 객체
DOM(문서 객체 모델) 노드로, DOM 노드 객체로 지정됩니다.
문서 객체 모델(DOM)은 World Wide Web Consortium에서 정의합니다. 자세한 내용은 XML 문서 객체 모델 항목을 참조하십시오.
버전 내역
R2006a 이전에 개발됨
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)