필터 지우기
필터 지우기

How to find and replace .tif in XML file In MATLAB

조회 수: 3 (최근 30일)
Hammad Younas
Hammad Younas 2023년 3월 6일
답변: Luca Ferro 2023년 3월 6일
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>

답변 (1개)

Luca Ferro
Luca Ferro 2023년 3월 6일
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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by