xmlwrite - Control the order of attributes

6 次查看(过去 30 天)
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

产品


版本

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by