xmlwrite - Control the order of attributes

조회 수: 1 (최근 30일)
Olaf Oelsner
Olaf Oelsner 2019년 1월 18일
댓글: Olaf Oelsner 2019년 1월 21일
Hi,
I wrote the following script to generate a XML-file...
xml_doc = com.mathworks.xml.XMLUtils.createDocument('Node');
root = xml_doc.getDocumentElement();
tool_elem = xml_doc.createElement('Tool');
tool_elem.setAttribute('name','me');
tool_elem.setAttribute('defaultValue','1122');
root.appendChild(tool_elem);
disp (xmlwrite(xml_doc));
... and I get the following result:
<?xml version="1.0" encoding="utf-8"?>
<Node>
<Tool defaultValue="1122" name="me"/>
</Node>
I know that the order is irrelevant from the point of the XML specification, but I would like to have the attribute "name" before "defaultValue" for readability.
Can I modify the order of the attributes?

채택된 답변

Jan
Jan 2019년 1월 18일
It is the nature of XML files, that the order of the attributes do not matter. Therefore I expect, that there is no way to determine the order. Some tests with different names look, like xmlwrite sorts the names of the attributes alphabetically. If you assume, that a modfied order of the attributes is easier to read, you have to access the text directly in an editor. Although this is possible and a wanted feature of XML, a smart XML viewer would be much better, especially if readability matters.
  댓글 수: 1
Olaf Oelsner
Olaf Oelsner 2019년 1월 21일
I agree to your arguments. I was just curious.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by