How to remove specific node in XML file?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
please see my "xml_sample.txt" file attached. I have 4 IP nodes (4 IP lines). I'd like to remove the last 2, so my new file would have only 2 IP nodes (the first 2).
If possible, I'd like to reduce the empty lines after removal as well. Please see "xml_sample_desiredOutput.txt" file attached.
I've tried to work with "removeChild", but could understand how to call it properly.
Can someone assist please? I'm pretty sure it's only ~3-4 lines of code.
- I'm using 2021b version.
THANKS.
0 Commenti
Risposte (1)
Shimon Elkin
il 18 Dic 2022
infoFile = fullfile(matlabroot,'toolbox/matlab/general/info.xml');
infoLabel = 'Plot Tools';
infoCbk = '';
itemFound = false;
import matlab.io.xml.dom.*
xDoc = parseFile(Parser,infoFile);
%Load File, create DOM node Object xDoc
ProductInfo = xDoc.Children;
%Create element object. This isn’t strictly necessary, but should increase the readability of the removeChild statement
removeChild(ProductInfo,ProductInfo.Children(10));
removeChild(ProductInfo,ProductInfo.Children(10));
%Remove both the node for the Matlab Icon from the object
xmlwrite(xDoc,’dummy.xml’);
%Write the contents of the object onto a new xml file
----------------------------------------------------------
Best of luck
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!