How do I convert a string to XML Dom Node?

조회 수: 17 (최근 30일)
Naum Derzhi
Naum Derzhi 2021년 12월 29일
답변: Mann Baidi 2023년 9월 15일
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