How to get a (root/parent/empty?) element?
5 views (last 30 days)
Show older comments
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?
Answers (1)
Sachin Lodhi
on 14 Nov 2023
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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!