Why does XMLREAD introduce extra whitespace into my .xml file?

조회 수: 7 (최근 30일)
I read in and export .xml files using the XMLREAD and XMLWRITE functions. If I read in and export to the same file without making any changes, additional whitespace characters are introduced.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2012년 4월 6일
The extra whitespace is introduced by the Saxon XML processor, which is the library that MATLAB uses for the XML processing.
To work around this issue, use the function below to automatically remove all extra new whitespaces and new lines in the XML file:
function xmlremoveextralines(filePath)
% Read file.
fId = fopen(filePath, 'r');
fileContents = fread(fId, '*char')';
fclose(fId);
% Write new file.
fId = fopen(filePath, 'w');
% Remove extra lines.
fwrite(fId, regexprep(fileContents, '\n\s*\n', '\n'));
fclose(fId);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structured Data and XML Documents에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by