今天就是在学习XML DOM编程过程中,出现了一个错误,浏览器总是告诉我有一个参数无效,后来经过认真研究终于找到了。
先把代码给大家看看吧。
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
<html>
3
<head>
4
<title></title>
5
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
6
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
7
</head>
8
<body onload="initializeBook();">
9
<h1> Wrox Press </h1>
10
<h3> Book Information </h3>
11
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
12
<TR>
13
<TD>Title:</TD><TD><input id="txtTitle"></TD>
14
</TR>
15
<TR>
16
<TD>Publisher:</TD><TD><input id="txtPublisher"></TD>
17
</TR>
18
<TR>
19
<TD>Published Date:</TD><TD><input id="txtPubDate"></TD>
20
</TR>
21
<TR>
22
<TD>Abstract:</TD><TD><input id="txtAbstract"></TD>
23
</TR>
24
<TR>
25
<TD>Pages</TD><TD><input id="txtPages"></TD>
26
</TR>
27
<TR>
28
<TD>ISBN:</TD><TD><input id="txtISBN"></TD>
29
</TR>
30
<TR>
31
<TD>Price:</TD><TD><input id="txtPrice"></TD>
32
</TR>
33
34
</TABLE>
35
36
<input type="button" id="btnUpdate" value="Update Book Info" onclick="updateBookInfo();" />
37
38
<h3>Author:</h3>
39
<table>
40
<tr>
41
<td>Author:</td><td><input id="txtAuthor"></td>
42
</tr>
43
</table>
44
<input type="button" id="btnAddAuthor" value="Add Author" onclick="addAuthor();" />
45
<h3>Catagories:</h3>
46
<table>
47
<tr>
48
<td>Category:</td><td><input id="txtCategory"></td>
49
</tr>
50
</table>
51
<input type="button" id="btnAddCategory" value="Add category" onclick="addCategory();"/>
52
53
<XML id=docBook>
54
<Book>
55
</Book>
56
</XML>
57
58
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
出现问题的代码是这一行:
1
function renderElements()
2
}
可见,是categoryXSL.documentElement这个参数出了问题,也就是XSL出了问题,但是笔者查了半天也没搞明白,最后终于找到了代码的问题,原来出现错误的代码是这样的:2
1 <XML id=categoryXSL>
2 <DIV xmlns:xsl="http://www.w3.org/TR/wd-xsl">
3 <table border="0" cellpadding="1">
4 <tr>
5 <td><strong>Categories</strong></td>
6 </tr>
7 <xsl:for-each select="/Book/RecSubjCategories/Category">
8 <tr>
9 <td><xsl:value-of select="text()" /></td>
10 </tr>
11 </xsl:for-each>
12 </table>
13 </div><!-- 这行出了问题 -->
14 </XML>
出问题的原因是,由于上面的<DIV xmlns:xsl="http://www.w3.org/TR/wd-xsl">是大写的,而结尾确是小写,自然会有问题,所以把</div>改为</DIV>就可以了,即:2 <DIV xmlns:xsl="http://www.w3.org/TR/wd-xsl">
3 <table border="0" cellpadding="1">
4 <tr>
5 <td><strong>Categories</strong></td>
6 </tr>
7 <xsl:for-each select="/Book/RecSubjCategories/Category">
8 <tr>
9 <td><xsl:value-of select="text()" /></td>
10 </tr>
11 </xsl:for-each>
12 </table>
13 </div><!-- 这行出了问题 -->
14 </XML>
<XML id=categoryXSL>
<DIV xmlns:xsl="http://www.w3.org/TR/wd-xsl">
<table border="0" cellpadding="1">
<tr>
<td><strong>Categories</strong></td>
</tr>
<xsl:for-each select="/Book/RecSubjCategories/Category">
<tr>
<td><xsl:value-of select="text()" /></td>
</tr>
</xsl:for-each>
</table>
</DIV>
</XML>
<DIV xmlns:xsl="http://www.w3.org/TR/wd-xsl">
<table border="0" cellpadding="1">
<tr>
<td><strong>Categories</strong></td>
</tr>
<xsl:for-each select="/Book/RecSubjCategories/Category">
<tr>
<td><xsl:value-of select="text()" /></td>
</tr>
</xsl:for-each>
</table>
</DIV>
</XML>