Search code examples
javascriptxmlxmldocumentxmlreader

Issue in reading an xml element string value from an xml document in javascript


About the application environment, I am trying to develop a webform in asp.net using c# and javascript.

I had an XML document, from which I am trying to retrieve values in javascript.

The XML contains six element string attributes, from which I am able to read 5 of them and facing an issue in reading the 6th value. One thing I had to mention is that, the 6th value is a url path.

Here's the following XML File data...

 <?xml version="1.0"?>
    <UnitData>
      <Unit>
        <Circle>Khammam</Circle>
        <Division>Paloncha</Division>
        <Range>Paloncha</Range>
        <UnitNo>24</UnitNo>
        <UnitName>Paloncha</UnitName>
        <KMLpath>http://fmis.telangana.gov.in/BLMIS/UnitKMLs/24/24_paloncha.kml</KMLpath>
      </Unit>
    </UnitData>

Here's the following Javascript code, from which I am trying to retrieve the values from XML.

var Circle = xmlDoc.getElementsByTagName("Circle")[i].childNodes[0].nodeValue;
var Division = xmlDoc.getElementsByTagName("Division")[i].childNodes[0].nodeValue;
var Range = xmlDoc.getElementsByTagName("Range")[i].childNodes[0].nodeValue;
var UnitNo = xmlDoc.getElementsByTagName("UnitNo")[i].childNodes[0].nodeValue;
var UnitName = xmlDoc.getElementsByTagName("UnitName")[i].childNodes[0].nodeValue;
var KMLpath = xmlDoc.getElementsByTagName("KMLpath")[i].chileNodes[0].nodeValue;

alert(KMLpath);

I'm able to retrieve the values of Circle, Division,Range,UnitNo,UnitName. But I can not read the KMLpath value, even the alert doesnt show up while executing the form.

I don't understand why I only can't read the value of an element string which contains an url.

Please suggest me up in this regard.

Regards, Sunny


Solution

  • By Changing the following line...it worked for me.

    var KMLpath = xmlDoc.getElementsByTagName("KMLpath")[i].textContent;