开发者

JScript runtime error with empty XML data

开发者 https://www.devze.com 2023-02-07 10:34 出处:网络
I have a script that 开发者_C百科creates an html table and appends data from an xml file to the table cells. In one case, the xml data is empty i.e. <event_title> </event_title>, so there

I have a script that 开发者_C百科creates an html table and appends data from an xml file to the table cells. In one case, the xml data is empty i.e. <event_title> </event_title>, so there is only a space. This causes a JScript runtime error "Object required" in IE8. I've tried lots of non-printing characters instead, no joy. Here's the offending line, but I don't think that should matter, I really just need to discover how to create an "object" here that won't break the script.

var eventTitle = (x[i].getElementsByTagName("event_title")[j].childNodes[0].nodeValue);


If event_title only contains text (no nested elements), you could try replacing

x[i].getElementsByTagName("event_title")[j].childNodes[0].nodeValue

with:

x[i].getElementsByTagName("event_title")[j].text

That's assuming you're using MSXML to parse the XML file (reference). .text will return an empty string if there's no text (or just whitespace).

0

精彩评论

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