Reputation: 2445
I'm trying to use a string variable as input to an xml function. When I use this command:
name2_node(i).setTextContent('truck');
there is no error. But when I replace it with:
name2_node(i).setTextContent(type(i,1));
an error occurs like this:
No method 'setTextContent' with matching signature found for class 'org.apache.xerces.dom.ElementImpl'.
The variable type is a string array. In fact when I type type(i,1)
in command window the result is:
ans =
string
"truck"
What part am I doing wrong?
Upvotes: 1
Views: 50
Reputation: 30046
Two things:
use a different variable name, type
is a built in function which tells you the variable type, hence why it shows "string" in the output.
Then access the cell array of strings with curly braces
vehicletypes = {'car'; 'truck'; 'van'};
name2_node(i).setTextContent(vehicletypes{i,1}); % For i=2, this passes 'truck'
Upvotes: 1