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?
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!