开发者

Difficulty in parsing the XML

I have been doing some XML parsing in my application. I used the following syntax to get the data from XML to my array:

v3[p]=''+xmlDoc.getElementsByTagName("vola开发者_开发问答tility_analysis3")[p].childNodes[0].nodeValue+'.';

but the problem is there is no data present in that particular node. It's like

<volatility_analysis3></volatility_analysis3>

so the parsing ends there. How to overcome that?


Check the length of xmlDoc.getElementsByTagName("volatility_analysis3"). If it is 0, move on.


Do it in steps like this

var node = xmlDoc.getElementsByTagName("volatility_analysis3")[p];
if (node.hasChildNodes())
 {
   v3[p]=''+node.childNodes[0].nodeValue+'.';
 }

If you are not sure there are p number of volatility_analysis3 nodes then add one more step

var nodelist = xmlDoc.getElementsByTagName("volatility_analysis3");
if (nodelist.length >= p )
 {
   var node = nodelist[p];
   if (node.hasChildNodes())
    {
      v3[p]=''+node.childNodes[0].nodeValue+'.';
    }
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜