MATLAB Answers

0

Change the value of a parameter in xml file using matlab

Asked by Zeynab Mousavikhamene on 26 Sep 2019
Latest activity Answered by Abhilash Padma on 1 Oct 2019
I have xml file and want to change a value of a parameter inside it. The line that has that specific parameter is:
<variable id="MIG" value="3" description="Change in MIG" />
I want to change value from 3 to other number.
I found these functions to read and write xml file:
DOMnode = xmlread('parameter.xml');
xmlwrite('newparameter.xml',DOMnode);
but not sure how to change the value of variable called "MIG".

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Abhilash Padma on 1 Oct 2019

To change the value of a parameter in an element, along with xmlread and xmlwrite, we need to use getElementsByTagName and setAttribute methods. See the following code where I have changed the value of parameter “value”.
test.xml
<variable id="MIG" value="3" description="Change in MIG" />
xDoc=xmlread(fullfile(('test.xml')));
allListItems=xDoc.getElementsByTagName('variable');
thisListItem=allListItems.item(0);
thisListItem.setAttribute('value','20');

  0 Comments

Sign in to comment.