非數(shù)據(jù)庫(kù)實(shí)現(xiàn)數(shù)據(jù)對(duì)象的實(shí)例及說(shuō)明
</tr>
</table>
</form>
</body>
</html>
三是利用代碼說(shuō)明xml存儲(chǔ)的實(shí)現(xiàn)
<% @LANGUAGE=VBSCRIPT %>
<!-- #include file="System.inc.asp" -->
<!-- #include file="Document.inc.asp" -->
<%
'System.inc.asp中包含UniqueID()函數(shù)
'首先,獲取用戶(hù)客戶(hù)端提交的數(shù)據(jù)信息
Dim PostData
Set PostData = Server.CreateObject("Scripting.Dictionary")
Dim Values, Key, Value, AttrID, Pos, Sign
For Each Key In DOCUMENTX
Sign = Left(Key, 1)
If Sign<>"*" Then
Value = DOCUMENTX.Item(Key)
Values = Split(Value & "%%%%%%", "%%")
Pos = InStrRev(Key, "/")
AttrID = Mid(Key, Pos + 1)
If Left(AttrID,1)="@" Then
AttrID = Mid(AttrID, 2) & "_INLINE" '也就是說(shuō)@為一般為內(nèi)置屬性
End If
AttrID = "ATTR_" & AttrID
If Sign="+" Then
Key = Mid(Key, 2)
End If
'If Sign="+" Then '系統(tǒng)屬性
'End If
PostData.Item(Key) = Request.Form(AttrID) '取得用戶(hù)提交的數(shù)據(jù)
End If
Next
'下面是把PostData中的數(shù)據(jù)存儲(chǔ)到XML中去
Dim oXml
Set oXml = Server.CreateObject("Msxml2.DOMDocument.4.0")
Dim TimeSpec, ZoneID, DocID, FName, FPath
'計(jì)算該文檔屬于的區(qū)域
'注意:創(chuàng)建新文檔與修改原有文檔的計(jì)算方式不同,這里只做了創(chuàng)建的處理
'新建文檔的處理
TimeSpec = Now
'ZoneID為YYYYMM形式
ZoneID = Right ("20" & Year(TimeSpec), 4) & Right("0" & Month(TimeSpec), 2)
FPath = ENVIRONMENT.Item("ROOT")
If Not FSO.FileExists(FPath & "\data\" & ZoneID & ".dat") Then
If Not FSO.FileExists(FPath & "\etc\blank.dat") Then
Application("*FAIL") = "系統(tǒng)配置不正確,空白數(shù)據(jù)模版文件未找到!"
Set oXml = Nothing
Set PostData = Nothing
Response.Redirect "Fail.asp"
End If
FSO.CopyFile FPath & "\etc\blank.dat", FPath & "\data\" & ZoneID & ".dat"
End If
oXml.load FPath & "\data\" & ZoneID & ".dat"
'由于這里處理的是新建的情況,所以指定新的DocumentID
PostData.Item("/DOCS/DOC/@ID") = UniqueID()
PostData.Item("/DOCS/DOC/@HOT") = "0"
DocumentSaveToXml PostData, oXml
oXml.save FPath & "\data\" & ZoneID & ".dat"
Set oXml = Nothing
Set PostData = Nothing
Response.Write "OK!"
%>
DocumentSaveToXml函數(shù)在Document.inc.asp中
<%
'DocumentSaveToXml
'目的:把Dict中的數(shù)據(jù)導(dǎo)入到指定的Xml對(duì)象中去
'說(shuō)明:如果Dict中指定ID的數(shù)據(jù)已經(jīng)存在于Xml中,則替換原有數(shù)據(jù)
Function DocumentSaveToXml(ByRef Dict, ByRef oXml)
DocumentSaveToXml = False
If Dict Is Nothing Or oXml Is Nothing Then
Exit Function
End If
Dim oXmlRoot, oXmlNode, oXmlSubNode
Set oXmlRoot = oXml.documentElement
Set oXmlNode = oXml.createElement("DOC")
Dim Key, Value
Dim Pos, AttrID, DocID
For Each Key In Dict
Value = Dict.Item(Key)
'根據(jù)Key
Pos = InStrRev(Key, "/")
AttrID = Mid(Key, Pos + 1)
If Left(AttrID, 1)="@" Then '如果是屬性
oXmlNode.setAttribute Mid(AttrID, 2), Value
Else
Set oXmlSubNode = oXml.createElement(AttrID)
oXmlSubNode.text = Value
oXmlNode.appendChild oXmlSubNode
End If
Next
'別忘了,這里的ID屬性定義,在documentx.dna中前面加上了+號(hào)
'也正是這些加*或者加+號(hào)屬性結(jié)構(gòu)不可以刪的原因
DocID = oXmlNode.getAttribute("ID")
Set oXmlSubNode = oXml.selectSingleNode("/DOCS/DOC[@ID=""" & DocID &