I have a callback function that returns an xml string which is a table of routes and corresponding miles.
xmlData=new ActiveXObject("Microsoft.XMLDOM");
xmlData.async="false";
xmlData.loadXML(returnmessage);
the xmlData.xml is this:
<NewDataSet>
<Routes>
<RouteName>StLouisToNewYork</RouteName>
<Miles>556</Miles>
</Routes>
<Routes>
<RouteName>MinneapolisToDallas</RouteName>
<Miles>948</Miles>
</Routes>
<Routes>
<RouteName>LosAngelesToDenver</RouteName>
<Miles>1033</Miles>
</Routes>
</NewDataSet>
In javascript, I would like to add a new route to my xmlData object.
var strRte = "DenverToAtlanta";
var strMi = "1408";
How do I do this? This is what I'm trying, but I'm throwing an error.
var newRoute = xmlData.createElement("Routes");
var nameNode = newRoute.createElement("RouteName"); <<<<<<<< Object doesn't support this property or method
var nameText = nameNode.createTextNode(strRte);
var milesNode = newRoute.createElement("Miles");
var milesText = milesNode.createTextNode(strMi);
newRoute.appendChild(nameNode);
newRoute.appendChild(milesNode);
xmlData.appendChild(newRoute);
I want my xmlData.xml to be this (Although I don't care which position):
<NewDataSet>
<Routes>
<RouteName>StLouisToNewYork</RouteName>
<Miles>556</Miles>
</Routes>
<Routes>
<RouteName>MinneapolisToDallas</RouteName>
<Miles>948</Miles>
</Routes>
<Routes>
<RouteName>LosAngelesToDenver</RouteName>
<Miles>1033</Miles>
</Routes>
<Routes>
<RouteName>DenverToAtlanta</RouteName>
<Miles>1408</Miles>
</Routes>
</NewDataSet>