xmlwrite : Attributes are alphabetically sorted

6 次查看(过去 30 天)
Hi
Does the xmlwrite() function use some sort of a sorting algorithm? When I execute the following code:
entry_node = docNode.createElement('myelement');
entry_node.setAttribute('name', myStruct.name);
entry_node.setAttribute('value', myStruct.value);
entry_node.setAttribute('unit', myStruct.unit);
docNode.getDocumentElement.appendChild(entry_node);
I get an XML file as follows:
<?xml version="1.0" encoding="utf-8"?>
<mySpec>
<myelement name="myName" unit="myUnit" value="myValue"/>
</mySpec>
What I need is:
<?xml version="1.0" encoding="utf-8"?>
<mySpec>
<myelement name="myName" value="myValue" unit="myUnit"/>
</mySpec>
Is there anyway to suppress the sorting algorithm(if any exists)?
Thanks in advance.
Regards, Vamsi

采纳的回答

Guillaume
Guillaume 2018-10-30
What I need is ...:
Then what you need is not xml. A compliant xml writer is explicitly allowed to order tags and attributes as it sees fit and a compliant xml reader is explicitly forbidden to rely on the ordering of tags and attributes. If your code relies on the order of the attributes, it does not follow the xml standard and will be broken by many xml writers.
Matlab delegate the xml writing to Java, so it is very likely that all writers based on Java will show the same behaviour.
  1 个评论
Vamsinag Gunti
Vamsinag Gunti 2018-10-30
Hi Guillaume,
Thank you for pointing out the error. Turns out that the format I wanted to generate was indeed wrong.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by