xmlwrite support for CDATA

1 Ansicht (letzte 30 Tage)
Neil
Neil am 20 Aug. 2012
Hi,
Am trying to use xmlwrite to generate an xmlfile with CDATA however the resulting xml does not wrap xml tags around the data e.g.
docNode = com.mathworks.xml.XMLUtils.createDocument('DataItem');
docRootNode = docNode.getDocumentElement;
thisElement = docNode.createElement('Sql');
thisElement.appendChild(docNode.createCDATASection('This should be in CDATA'));
docRootNode.appendChild(thisElement);
xml = xmlwrite(docNode);
disp(xml)
Results in
<?xml version="1.0" encoding="utf-8"?>
<Sql>This should be in CDATA</Sql>
When I would expect
<?xml version="1.0" encoding="utf-8"?>
<Sql> <![CDATA[This should be in CDATA]]></Sql>
Am I doing something wrong here, I am not an XML expert

Antworten (1)

Dave
Dave am 20 Aug. 2012
This appears to be a widely reported problem. It seems that you can hard-code the delimiters as follows: thisElement.appendChild(docNode.createCDATASection(['<![CDATA[','This should be in CDATA',']]>']));

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by