How do I convert a string to XML Dom Node?

19 次查看(过去 30 天)
I have a file, part of which contains a string representing an XML DOM node. I have this whole string in memory as a char variable. Is there a way to convert it to DOM node, without using an intermediate file?

回答(1 个)

Mann Baidi
Mann Baidi 2023-9-15
Hi Naum,
I understand you would like to convert a string to XML Dom Node without converting it to a file.
I suggest you use the “parseString” function in MATLAB. For using it you will have to import “matlab.io.xml.dom.* ”. However, I would still advise you to use “xmlread” function using the file as “parseString” will not make the children nodes.
Here is an example code of parseString:
import matlab.io.xml.dom.*
s1 = "<days><day>Mon</day><day>Tue</day><day>Wed</day>";
s2 = "<day>Thu</day><day>Fri</day></days>";
xmlString = s1+s2;
doc = parseString(Parser,xmlString);
x= parseChildNodes(doc);
For more information, you can refer the documentation of the “parseString” function:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Structured Data and XML Documents 的更多信息

标签

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by