非數據庫實現數據對象的實例及說明
</tr>
</table>
</form>
</body>
</html>
三是利用代碼說明xml存儲的實現
<% @LANGUAGE=VBSCRIPT %>
<!-- #include file="System.inc.asp" -->
<!-- #include file="Document.inc.asp" -->
<%
'System.inc.asp中包含UniqueID()函數
'首先,獲取用戶客戶端提交的數據信息
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" '也就是說@為一般為內置屬性
End If
AttrID = "ATTR_" & AttrID
If Sign="+" Then
Key = Mid(Key, 2)
End If
'If Sign="+" Then '系統屬性
'End If
PostData.Item(Key) = Request.Form(AttrID) '取得用戶提交的數據
End If
Next
'下面是把PostData中的數據存儲到XML中去
Dim oXml
Set oXml = Server.CreateObject("Msxml2.DOMDocument.4.0")
Dim TimeSpec, ZoneID, DocID, FName, FPath
'計算該文檔屬于的區域
'注意:創建新文檔與修改原有文檔的計算方式不同,這里只做了創建的處理
'新建文檔的處理
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") = "系統配置不正確,空白數據模版文件未找到!"
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函數在Document.inc.asp中
<%
'DocumentSaveToXml
'目的:把Dict中的數據導入到指定的Xml對象中去
'說明:如果Dict中指定ID的數據已經存在于Xml中,則替換原有數據
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)
'根據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中前面加上了+號
'也正是這些加*或者加+號屬性結構不可以刪的原因
DocID = oXmlNode.getAttribute("ID")
Set oXmlSubNode = oXml.selectSingleNode("/DOCS/DOC[@ID=""" & DocID &