xmlwrite support for CDATA

1 回表示 (過去 30 日間)
Neil
Neil 2012 年 8 月 20 日
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

回答 (1 件)

Dave
Dave 2012 年 8 月 20 日
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',']]>']));

カテゴリ

Help Center および File ExchangeStructured Data and XML Documents についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by