How to find and replace .tif in XML file In MATLAB
Show older comments
Hello, I hope you are doing well. I have the following XML files in folder.
I want to read all files from folder and read the file and change the file extenstion .tif with jpg in XML file.
as you can se below i have the following like where image is in .tif i want to convert end .tif with jpg
input:
<filename>000000000000.tif</filename>
output:
<filename>000000000000.jpg</filename>
Can anybody help me with this.
I have used Notepad++ for this
The xml file is not attaching so i can paste the input of .XML file
<?xml version="1.0"?>
-<annotation>
<filename>000000000002.tif</filename>
-<source>
<annotation>ESRI ArcGIS Pro</annotation>
</source>
-<size>
<width>128</width>
<height>128</height>
<depth>3</depth>
</size>
-<object>
<name>1</name>
-<bndbox>
<xmin>85.82</xmin>
<ymin>0.00</ymin>
<xmax>128.00</xmax>
<ymax>11.95</ymax>
</bndbox>
</object>
-<object>
<name>1</name>
-<bndbox>
<xmin>42.56</xmin>
<ymin>0.00</ymin>
<xmax>85.88</xmax>
<ymax>6.05</ymax>
</bndbox>
</object>
</annotation>
Answers (1)
Luca Ferro
on 6 Mar 2023
0 votes
Try this:
xmlFileDOM = xmlread('totallyAXml.xml'); %reads xml to dom
xmlFileStr=string(xmlwrite(xmlFileDOM)); %cast dom to string
newXML=strrep(xmlFileStr,'.tif','.jpg');%changes tif to jpg
fID=fopen('totallyAXml.xml','w'); %opens xml
fprintf(fID,newXML); %overwrites
fclose(fID); %close and save
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!