Create XML with document name and attributtes
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!