# StringJoin Dynamic problem [duplicate]

My goal is to import a XML file from the site fueleconomy.gov to get a list of cars dependent on the year given as the user input .

Here is the code:

years = Import["http://www.fueleconomy.gov/ws/rest/vehicle/menu/year", "XML"];
y = Cases[years, XMLElement["menuItem", _, _], Infinity] /.
XMLElement[_, _, {val_}] ->  val /.
Do[y[[i]] = DeleteDuplicates[y[[i]]], {i, 1, Length[y], 1}];
years = y[[All, 1]]

makes = Import[
StringJoin[
year], "XML"];


I tried to put Dynamic[year] instead of year but it crashes en got this error:

"String expected at position 2 in

My question is why StringJoin put '<>' in the url in the error message. I used the same function before and it worked, any ideas?

• The problem is that Dynamic puts an invisible wrapper around its argument so that StringJoin does not see it as a String anymore. year itself is a number and no String, so you should use ToStringon it. The <> in the error message is simply the infix form of StringJoin (see its doc page). – Sjoerd C. de Vries Jul 22 '15 at 10:24
• Yes, I watched it, the solution gived by the page don't work it says that ToString[exp] solved it but if I do that with my variable it return Dynamic[year] and no the value – Alberto Jul 22 '15 at 10:31
• Which page are you referring to? As I wrote in my above comment you cant use Dynamic[year] where a string is expected as that simply isn't a string. If I replace year in your last line with ToString[year] the code works. – Sjoerd C. de Vries Jul 22 '15 at 10:34
• reference.wolfram.com/language/ref/StringJoin.html reference.wolfram.com/language/ref/Join.html reference.wolfram.com/language/ref/Flatten.html I see this references and year is a string the xml file have two elements text and value and i get text Also i try to put Dynamic[..] englobing makes =Import[...] and it works – Alberto Jul 22 '15 at 10:38
• You don't write this in your question, but is your intention to have the makes variable updated automatically when the user selects a new year from the pop-up menu? – Sjoerd C. de Vries Jul 22 '15 at 10:43

Moving it to a Manipulate sounds like a better idea:

Manipulate[
makes = Import[
StringJoin[