필터 지우기
필터 지우기

How to get a (root/parent/empty?) element?

조회 수: 7 (최근 30일)
Wu Yu-Wei
Wu Yu-Wei 2023년 7월 12일
답변: Sachin Lodhi 2023년 11월 14일
Hi,
my xml data have two ParentElements <Devices> and <Params>, both have many elements <param... >.
paralist = getElementsByTagName(xDoc,'param');
I get <param ...> element from both parentelements.
It there any method to get these two ParentElements first before getting their childrelement?
  댓글 수: 2
Wu Yu-Wei
Wu Yu-Wei 2023년 7월 13일
I read the document in w3c.org about the structure,and tried example from here:
paralist = getElementsByTagName(xDoc,'listitem');
But I still don't understand how to get the ParentElement <list>.
Wu Yu-Wei
Wu Yu-Wei 2023년 7월 17일
I used a function by Joe to parse the xml into a structure, and dig out my interest
so I can handle my data for now.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sachin Lodhi
Sachin Lodhi 2023년 11월 14일
Hi Wu Yu-Wei,
Based on my understanding, it appears that you are interested in obtaining the root or parent element of your XML data file. For this, MATLAB provides an option to import an XML file into a Document Object Model (DOM) document node using a ‘matlab.io.xml.dom.Parser’ object or the ‘xmlread’ function.
After creating the DOM node, you can use the ‘getElementsByTagName’ method to get the parent elements, and use the ‘getChildNodes’ method to access their child elements.
Please refer to the following document for additional information and examples related to these methods - https://www.mathworks.com/help/matlab/ref/matlab.io.xml.dom.nodelist-class.html#:~:text=Public%20Methods-,Examples,-collapse%20all
I hope this helps.
Best Regards,
Sachin

카테고리

Help CenterFile Exchange에서 Structured Data and XML Documents에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by