xmlwrite - Control the order of attributes
    2 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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 Commenti
Risposta accettata
  Jan
      
      
 il 18 Gen 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.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

