writestruct() fails to write empty child element to XML file
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I need to write a empty, nested element within an XML file. An XML example of what I'd like to achieve is:
<?xml version="1.0" encoding="UTF-8"?>
<Problem>
<elementA>14</elementA>
<elementB>
<child/>
</elementB>
</Problem>
The nested element in this case is called "child". I expected the following MATLAB code to produce this result:
s.elementA = 14;
s.elementB.child = [];
writestruct(s,'test.xml','StructNodeName','Problem')
However, this generates the following XML, whereupon the "child" element is entirely missing:
<?xml version="1.0" encoding="UTF-8"?>
<Problem>
<elementA>14</elementA>
<elementB/>
</Problem>
How can I produce a result with an empty, nested element?
0 comentarios
Respuesta aceptada
Voss
el 12 de Jun. de 2024
s.elementA = 14;
s.elementB.child = struct();
writestruct(s,'test.xml','StructNodeName','Problem')
type('test.xml')
2 comentarios
Más respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!