フィルターのクリア

Create XML with document name and attributtes

4 ビュー (過去 30 日間)
Giri
Giri 2018 年 3 月 21 日
回答済み: zhuofei wu 2022 年 9 月 16 日
Hi,
I am developping a code to create an XML document from data retrived from an excel sheet. The requirement is such that, the XML document node should be off the following format:
<sce xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.5">
<Scenario>
<description>...</description>
<name/>
</Scenario>
</sce>
The XML that i am creating comes out as below:
<sce>
<Scenario>
<description>...</description>
<name/>
</Scenario>
</sce>
i.e i am not able to create the attributes of the document node which are xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.5"
I have the attrbutes and the corresponding values in a container map as seen below:
objScenarioDocDetails.cm_docAttributes= containers.Map(arrAttributesKeySet,arrAttributesValueSet);
Any help to fix this issue would be greatly appreaciated. Thanks in advance.

回答 (1 件)

zhuofei wu
zhuofei wu 2022 年 9 月 16 日
try this:
import matlab.io.xml.dom.*
docNode = Document("sce");
docRootNode = getDocumentElement(docNode);
docRootNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
docRootNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "version", "1.5");
xmlFileName = "example_ns.xml";
writer = matlab.io.xml.dom.DOMWriter;
writer.Configuration.FormatPrettyPrint = true;
writeToFile(writer,docNode,xmlFileName);
type(xmlFileName);
The explaination could be found at: https://stackoverflow.com/a/11146971/9173213

カテゴリ

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