xmlwrite - Control the order of attributes
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Jan
le 18 Jan 2019
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.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!