How to call xml (title) tags using Javascript

html, javascript, xml

Solution

try by

var name = xmlDoc.getElementsByTagName("design");
var value = name[0].getAttribute('title')
alert(value);

also in the w3school example, the `loadXMLDoc` is a function which is defined manually. It uses `XMLHttpRequest()` and `ActiveXObject("Microsoft.XMLHTTP")` According to your browser type. So if you dint include `loadXMLDoc` definition, then there will be errors.

Problem

I have one xml file which main root starts with: ``` <design title="standard Cards 3.5 x 2" > <previews></previews> <previews1></previews1> <previews2></previews2> </design> ``` I want to read that xml files and get title tags and assign in option value. I also got this `design` root tags by using this w3school method .i want to get `design` --> `title` and stored into my select box: Here my code: ``` var selectHTML = ""; selectHTML += "<select name='something' id='media' onchange='select();'>"; for (i = 0; i < total.length; i = i + 1) { if (total[i] != '') { xmlDoc = loadXMLDoc($loc); var fruits = xmlDoc.documentElement.nodeName; if (fruits) { alert(fruits); var name = xmlDoc.getElementsByTagName("design") alert(name); } selectHTML += "<option value='" + total[i] + "'>" + name + "</option>"; } } selectHTML += "</select>"; ``` Here `xmlDoc=loadXMLDoc($loc);` is calling method of xml files.I refer this from w3school tutorial I just alerting `name` it resulting undefined. How to solve this? I want to place `name` value into my select box option value. How to read xml files using javascript and place into option value?

Original source

Related problems