How to create XML file without the first line of <?xml version="1.0" encoding="utf-8"?>

27 ビュー (過去 30 日間)
Mark Golberg
Mark Golberg 2022 年 2 月 13 日
コメント済み: Mark Golberg 2022 年 2 月 14 日
Hello,
if I use:
DOMnode = readxml(my_file_name_source);
writexml(DOMnode , my_file_name_target);
I'll get the same XML file with the addition of:
<?xml version="1.0" encoding="utf-8"?>
How can I create my new file without that auto generated line?
THANKS

採用された回答

Voss
Voss 2022 年 2 月 13 日
You could do something like this, which first writes the xml file as usual (with the first line) using xmlwrite(), then reads the file into a variable, removes the first line, and writes the rest back to the same file.
DOMnode = xmlread(my_file_name_source);
xmlwrite(DOMnode , my_file_name_target);
% read the xml file
fid = fopen(my_file_name_target,'r');
data = fread(fid);
fclose(fid);
% remove the first line
idx = find(data == newline(),1);
if ~isempty(idx)
data(1:idx) = [];
end
% write the remaining contents back to the same file
fid = fopen(my_file_name_target,'w');
fwrite(fid,data);
fclose(fid);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructured Data and XML Documents についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by