should work:
local carName = "car" .. xmlNodeGetAttribute(v, "num")
local car = createVehicle(carmodel, carX, carY, carZ, 0.0, 0.0, carA)
setElementID(car, carName)
When you want to join strings together in Lua you use .. not +
You also had set carName to the string, and then overwrote it with the return from createVehicle() thats the reason it wasnt working.