【发布时间】:2011-12-28 21:59:55
【问题描述】:
我正在尝试通过使用 jquery 解析 XML 文件来创建表。 XML 文件如下所示...
<?xml version='1.0' encoding='UTF-16'?>
<E1TC NAME='R584211WXB' VERSION='a'>
<TextLine1>
<1>2011/11/06</1>
<2>5748283</2>
<3>10.9300</3>
<4>4049027</4>
<5>7.7000</5>
<6>42799422</6>
<7>81.3800</7>
<8>52596733</8>
</TextLine1>
<TextLine1>
...
</TextLine1>
</E1TC>
我的 jquery 函数是这样的
// Build an HTML string
myHTMLOutput = '';
myHTMLOutput += '<table width="98%" border="1" cellpadding="0" cellspacing="0">';
myHTMLOutput += '<th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th>';
// Run the function for each TextLine1 tag in the XML file
$('TextLine1',xml).each(function(i)
{
d1 = $(this).find("1").text();
d2 = $(this).find("2").text();
d3 = $(this).find("3").text();
d4 = $(this).find("4").text();
d5 = $(this).find("5").text();
d6 = $(this).find("6").text();
d7 = $(this).find("7").text();
d8 = $(this).find("8").text();
d1Post = $(this).find("1").attr("post");
// Build row HTML data and store in string
mydata = BuildStudentHTML(d1,d2,d3,d4,d5,d6,d7,d8,d1Post);
myHTMLOutput = myHTMLOutput + mydata;
});
myHTMLOutput += '</table>';
输出生成一个带有标题 1、2、3、..、8 的空白表。我找不到我的错误。我知道这段代码有效,因为它是来自http://www.compoc.com/tuts/ 的示例。当我修改它以使用我的 XML 文档时,出现了问题。这条线好像有问题
$('TextLine1',xml).each(function(i)
关于如何解决它的任何想法?这是我第一次使用 jquery...
【问题讨论】:
-
如果我在 $('TextLine1',xml).each(function(i){ 我不会收到任何输出。但如果我把它放在那行之前,我会看到输出。
标签: javascript jquery xml parsing