Add a comment line into a XML file

조회 수: 4 (최근 30일)
Davide Luigi Perego
Davide Luigi Perego 2014년 4월 25일
답변: Ricardo Zetina 2018년 2월 21일
Hi, I am creating a XML file from scratch as in the following:
% Create the root element
docNode = com.mathworks.xml.XMLUtils.createDocument('Standard:Report');
docRootNode = docNode.getDocumentElement;
I'd like to add a comment line right after the usual XML declaration. Does anybody know how to do that? Many thanks in advance. Regards Davide

답변 (1개)

Ricardo Zetina
Ricardo Zetina 2018년 2월 21일
This is a pretty old post, but I needed to do the same and found the solution, so posting so others can don't need to spend a lot of time looking for this.
new_comment = docNode.createComment('This is a comment');
docNode.appendChild(new_comment);
if you need more information search for DOM.

카테고리

Help CenterFile Exchange에서 Structured Data and XML Documents에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by