Professional_XML

所属分类:xml/soap/webservice
开发工具:Visual C++
文件大小:219KB
下载次数:29
上传日期:2006-06-05 07:50:36
上 传 者cqlnet
说明:  《XML高级编程》配书源码 【原书名】 Professional XML 【原出版社】 Wrox Press 【作者】 Didier Martin
( "The XML High-level Programming" matches the book source code [ original book title ] Professional XML [ original publishing house ] Wrox Press [ author ] Didier Martin )

文件列表:
Chapter 02 (0, 2000-06-12)
Chapter 02\catalog.xml (5292, 2000-03-13)
Chapter 03 (0, 2000-06-12)
Chapter 03\BookCatalog.dtd (1796, 1999-11-11)
Chapter 05 (0, 2000-06-12)
Chapter 05\book.txt (353, 1999-12-02)
Chapter 05\BookClient.htm (7960, 1999-12-10)
Chapter 05\BookForm.htm (195, 1999-12-10)
Chapter 05\browserdetect.htm (401, 1999-11-15)
Chapter 05\DisplayBook.asp (6870, 1999-12-10)
Chapter 05\DisplayBook2.asp (7342, 1999-12-10)
Chapter 05\DisplayBook3.asp (7847, 1999-12-10)
Chapter 05\DisplayBook4.asp (8209, 1999-12-10)
Chapter 06 (0, 2000-06-12)
Chapter 06\AveragePrice.java (1589, 1999-11-02)
Chapter 06\AveragePrice1.java (3141, 1999-11-03)
Chapter 06\AveragePrice1_ibm.java (3152, 1999-11-03)
Chapter 06\AveragePrice2.java (1899, 1999-11-02)
Chapter 06\AveragePrice_ibmSAX.java (1914, 1999-11-02)
Chapter 06\BookCounter1.java (716, 1999-11-01)
Chapter 06\books.xml (431, 1999-11-05)
Chapter 06\books1.xml (1058, 1999-11-03)
Chapter 06\DisplayBookList.java (2937, 1999-11-05)
Chapter 06\ElementHandler.java (665, 1999-11-04)
Chapter 06\Indenter.java (4799, 1999-11-05)
Chapter 06\Switcher.java (1448, 1999-11-04)
Chapter 06\XMLOutputter.java (5249, 1999-11-04)
Chapter 07 (0, 2000-06-12)
Chapter 07\Authors.xml (924, 1999-08-17)
Chapter 07\PubCatalog.xml (3846, 1999-08-19)
Chapter 07\SchemaConcordance.html (4663, 1999-08-17)
Chapter 08 (0, 2000-06-12)
Chapter 08\catalog.xml (5292, 2000-03-13)
Chapter 08\ColumnWise.xsl (583, 2000-01-31)
Chapter 08\InnerJoin.xsl (732, 2000-01-31)
Chapter 08\MultiSource.xsl (656, 2000-01-31)
Chapter 08\OuterJoin.xsl (1121, 2000-01-31)
Chapter 08\Procedural.xsl (864, 2000-01-31)
Chapter 08\RowWise.xsl (566, 2000-01-31)
Chapter 08\Sort.xsl (624, 2000-01-31)
... ...

The code for this chapter is slightly different to that in the book due to a few teething troubles with the original. The changes are: 1. If the tag holding the results is a DIV it makes copying the results to the clipboard slightly easier. We need to change from XMP to DIV at the bottom of page 483. 2. If an element occurred more than once it was getting a column for each occurrence (see page 474 of the book for the bit where this is discussed). The following therefore needs to go into the block of code at the bottom of page 485: var bMulti = false; var oTempNL = oNode.parentNode.selectNodes( "element[@type='" + sType+ "']" ); if (oTempNL.length > 1) { i += (oTempNL.length - 1); bMulti = true; } bMulti = bMulti || (getAttr(oNode, "maxOccurs") == "*"); This involves stepping past (by adding to i) any elements that are of the same type as the one we are looking at. I'm careful to check only in the current context, since there could be elements with the same name elsewhere in the tree. If we wanted to be more accurate about our resulting SQL we might add a SQL trigger here to detect the exact number of elements that are allowed to be added - my version simply makes this a multi. 3. The foreign key values were being set to varchar(255). This was because the new column was being created as a default column, not an INT. Therefore we need to change the last line of the CreateRel function at the bottom of page 491: function CreateRel(sT1, sFK, sT2, sPK) { // Create an instruction to generate a foreign key var oTemp = oParsOut.createElement("FK"); oTemp.setAttribute("table1", sT1); oTemp.setAttribute("src", sFK); oTemp.setAttribute("table2", sT2); oTemp.setAttribute("dest", sPK); oDBFK.appendChild(oTemp); NewColumnINT(sT1, sFK); } 4. The same goes for the ID values that were being created. This meant that foreign keys could not match the primary keys. We need to change the last line of the CreateID function (at the top of page 490): function CreateID(s, c) { var oTemp = oParsOut.createElement("ID"); c = "attr_id_" + c; oTemp.setAttribute("table", s); oTemp.setAttribute("name", c); oDBID.appendChild(oTemp); // Add the column to the create table node NewColumnINT(s, c); } 5. The problem with these changes is that making foreign keys always refer to integers screws up the way I have done the enumerations for things like headquarters and currencies. At the moment they simply have one column, containing the various values. I have now changed this so that they have a primary key of type integer, like all other tables. This requires two lots of changes. The first lot make the table have an incrementing integer for a primary key, and a column to hold the enumerated values, which is in the middle block of code on page 485: // - each AttributeType which has a type of 'enumeration' oNL = oDE.selectNodes("//AttributeType[@dt:type='enumeration']"); for (var i = 0; i < oNL.length; i++) { sTable = "enum_" + oNL(i).attributes.getNamedItem("name").value; CreateTABLE(sTable, true); NewColumnDEF(sTable, "enum_value"); CreateDATA( sTable, oNL(i).attributes.getNamedItem("dt:values").value ); } The second inserts the enumerated values in the right columns. At the end of the SQL XSL script we need to change the 'Insert' template (not listed in the book): Insert dbo. (enum_value) Values('') Go This is all working fine in SQL Server 7.0, but I don't have SQL Server 6.0 any more. However, there is nothing in here that is not standard SQL. so it should be fine. 6. The only final thing I had to do to make it work with the schemas in the book was to paste the Authors.xml schema directly into the PubData.xml schema. Obviously you could add code to follow through the namespace to the second schema, but I haven't got time to do it, and I don't think it really is the purpose of the demonstration anyway, so I don't think there is much loss there. It may mean that you need to provide a second version of PubData.xml - the one I have enclosed here. Note that there is an occurrence of type rather than dt:type in the original PubData.xml, but I can't find it again because I have corrected it. You may wish to check your copies to see if it has been corrected yet on your side.

近期下载者

相关文件


收藏者