Filter löschen
Filter löschen

XML write set attribute with xml namespace

12 Ansichten (letzte 30 Tage)
vivek patel
vivek patel am 9 Mär. 2023
Kommentiert: vivek patel am 16 Mär. 2023
I am trying to write an xml file, where i need to write the xml namespace and its URI as below.
<node xmlns:xml="http://www.w3.org/XML/1998/namespace" >
......
.....
</node>
I understand that this is completely optional and its okay if we don't write it. But i need it as that is expected to be done.
I am using xmlwrite function as using older matlab version, so don't have writeStruct function. When i am writing below code somehow matlab is not writing the xml namespace in the xml file. I think it is because it is preserved but i am not able to get any workaround it.
Can you please help on this ?
docNode = com.mathworks.xml.XMLUtils.createDocument('node');
rootElement = docNode.getDocumentElement;
rootElement.setAttribute('xmlns:xml','http://www.w3.org/XML/1998/namespace');
rootElement.setAttribute('xmlns:2xml','http://www.w3.org/XML/1998/namespace');
xmlwrite('test.xml',docNode);
  2 Kommentare
Mihai
Mihai am 11 Mär. 2023
Try:
docNode = com.mathworks.xml.XMLUtils.createDocument('node');
rootElement = docNode.getDocumentElement;
rootElement.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xml', 'http://www.w3.org/XML/1998/namespace');
vivek patel
vivek patel am 16 Mär. 2023
Hi,
I tried but unfortunately it is not working, i have tried in MATLAB 2016b and MATLAB 2021a versions. Is it working in some other versions ?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by