Hadi GhahremanNezhad
Hadi GhahremanNezhad

Reputation: 2445

error with string variable

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

Answers (1)

Wolfie
Wolfie

Reputation: 30046

Two things:

  1. 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.

  2. 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

Related Questions