xmlwrite in script does not produce a file

조회 수: 4 (최근 30일)
S vC
S vC 2019년 1월 24일
답변: Nick Trajkovski 2019년 1월 30일
Hello community,
I encountered a strange problem using xmlwrite in a script.
Below is the part which creates the xml file.
docNode = com.mathworks.xml.XMLUtils.createDocument('testsuite');
testsuite = docNode.getDocumentElement;
testsuite.setAttribute('name',Functionname);
testsuite.setAttribute('disabled',num2str(NumberOfDisabledTests));
testsuite.setAttribute('errors',num2str(NumberOfErrors));
testsuite.setAttribute('failures',num2str(NumberOfFailures));
testsuite.setAttribute('tests',num2str(NumberOfTests));
%Create Test case element
for idx = 1:length(TestfallNamenListe)
test_node = docNode.createElement('testcase');
test_node.setAttribute('name',TestfallNamenListe{idx});
test_node.setAttribute('classname',Functionname);
test_node.setAttribute('status',StatusListe{idx});
docNode.getDocumentElement.appendChild(test_node);
if strcmp(FailureTextListe{idx},'')
% do not add a failure node
else
failure_node = docNode.createElement('failure');
failure_text = docNode.createTextNode(FailureTextListe{idx});
failure_node.appendChild(failure_text);
test_node.appendChild(failure_node);
end
if strcmp(ErrorTextListe{idx},'')
% do not add a failure node
else
error_node = docNode.createElement('error');
error_text = docNode.createTextNode(ErrorTextListe{idx});
error_node.appendChild(error_text);
test_node.appendChild(error_node);
end
end
% Write to file
disp('Write XML file.');
xmlFilename = ['..\', 'Testresult_', Functionname, '.xml'];
xmlwrite(xmlFilename,docNode)
disp('Done.');
quit
Executing the script from cmd.exe with
matlab -automation -r "run('ABSPATHTOFOLDER\software\model\startup.m');run('ABSPATHTOFOLDER\AddCarnotPaths.m');run('ABSPATHTOFOLDER\software\test\JenkinsTests')" -logfile ABSPATHTOFOLDER\intermediate\TestLog.log -wait
does not create a xml file.
The strange thing is that if I comment out
quit
and execute
xmlwrite(xmlFilename,docNode)
manually in the command line window of Matlab I get the xml file with the correct content.
This means that programatically everything seems to be ok.
Does anyone have a explanatoin why xmlwrite per automation switch does not create the expected file?
Thanks in advance
Best regards

답변 (1개)

Nick Trajkovski
Nick Trajkovski 2019년 1월 30일
Hi,
The issue occurs since the quit command in your script closes the MATALB session so any scripts following the quit command do not execute. I commented out the quit command and instead added it to the list of the command line parameters:
matlab -automation -r "run('ABSPATHTOFOLDER\software\model\startup.m');run('ABSPATHTOFOLDER\AddCarnotPaths.m');run('ABSPATHTOFOLDER\software\test\JenkinsTests'); quit;" -logfile ABSPATHTOFOLDER\intermediate\TestLog.log -wait
This sholud fix the issue you are running into.

카테고리

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

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by