作者:大自然一段合并XML的代码,我也是从MS的XML帮助这里抄来的。。相信对新手有帮助[转](0分)

  • 主题发起人 主题发起人 netnice
  • 开始时间 开始时间
N

netnice

Unregistered / Unconfirmed
GUEST, unregistred user!

将以下代码直接存成一个HTML文件就行了。。然后可以一边看效果一边更改一些代码。。。
<XML ID="file1">
<COLLECTION xmlns:dt="urn:schemas-microsoft-com:datatypes">
<DATE dt:dt="datetime">1998-10-13T15:56:00</DATE>
<BOOK>
<TITLE>Cosmos</TITLE>
<AUTHOR>Carl Sagan</AUTHOR>
<PUBLISHER>Ballantine Books</PUBLISHER>
</BOOK>
<BOOK>
<TITLE>Catwings</TITLE>
<AUTHOR>Ursula K. Le Guin</AUTHOR>
<PUBLISHER>Scholastic</PUBLISHER>
</BOOK>
</COLLECTION>
</XML>
<XML ID="file2">
<COLLECTION>
<BOOK>
<TITLE>Inside MSXML</TITLE>
<AUTHOR>Microsoft</AUTHOR>
<PUBLISHER>The MS Press</PUBLISHER>
</BOOK>
<BOOK>
<TITLE>无废话XML</TITLE>
<AUTHOR>两只老虎</AUTHOR>
<PUBLISHER>台湾</PUBLISHER>
</BOOK>
<BOOK>
<TITLE>Home Town</TITLE>
<AUTHOR>Tracy Kidder</AUTHOR>
<PUBLISHER>Random House</PUBLISHER>
</BOOK>
</COLLECTION>
</XML>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<script language="vbscript" id="mergeFunction">
Dim xmldoc
Dim xmldoc2
' Firstdo
cument.
Set xmldoc = file1.XMLDocument
' Seconddo
cument.
Set xmldoc2 = file2.XMLDocument
function merge_xml()
Dim iIndex
Dim xmlNode
Dim NodeList

Set NodeList = xmldoc2.selectNodes("*/BOOK")
' Merge.

For iIndex = 0 To NodeList.length - 1
Set xmlNode = NodeList.Item(iIndex).cloneNode(True)
xmldoc.documentElement.appendChild xmlNode
Next
end function
</script>
<script language="vbscript">
function mergeAndShow()
merge_xml()
showDoc(1)
Showfile1.value="Show Merged File"
end function
function showDoc(iIndex)
select case iIndex
case 1 GeneralDisplayBox.value=xmldoc.xml
case 2 GeneralDisplayBox.value=xmldoc2.xml
case else
GeneralDisplayBox.value=""
end select

end function
</script>
<BODY>
<PRE>
<script language="vbscript">
do
cument.writelndo
cument.scripts.item("mergefunction").text
</script>
</PRE>
<TABLE border='2'>
<TR>
<TD>
<TEXTAREA title='General Display' id='GeneralDisplayBox' rows='20' cols='60' readonly></TEXTAREA>
</TD>
<TD width='90'>
<TABLE>
<TR align=center>
<TD>
<input id='Showfile1' type='button' value="Show File1" onclick="showDoc(1)" />
</TD>
</TR>
<TR align=center>
<TD>
<input type='button' value="Show File2" onclick="showDoc(2)" />
</TD>
</TR>
<TR align=center>
<TD>
<input type='button' value="MergeFiles" onclick="mergeAndShow()"/>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<P>&amp;nbsp;</P>
</BODY>
</HTML>
 
接受答案了.
 
后退
顶部