DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> XML學習教程 >> XML詳解 >> 讀取XML的類 XmlReader
讀取XML的類 XmlReader
編輯:XML詳解     

 還有一個讀取XML的類 XMLReader:

<%
Class XMLReader

Private XML

Public Sub Load(ByVal Path)
XML.Load(Server.MapPath(Path))
End Sub

Public Function SelectSingleNode(ByVal XPath)
Set SelectSingleNode = XML.SelectSingleNode(XPath)
End Function

Public Function SelectNodes(ByVal XPath)
Set SelectNodes = XML.SelectNodes(XPath)
End Function

Private Sub Class_initialize()
Set Xml = Server.CreateObject("Microsoft.XMLDOM")
XML.async = False
''XML.setProperty "ServerHTTPRequest", True
End Sub
Private Sub Class_Terminate()
Set XML = Nothing
End Sub

End Class
%>

  好了,萬事俱備,開始搭建基本的三層:

  數據模型層:此層對應成一個類,類的類名和字段屬性對應於數據庫的相應表名及字段。

  考慮表News,其結構如下:

  則其對應的模型層如下:

<%
Class DataNews

Private IAddDate
Private IContent
Private ICount
Private INewsID
Private ITitle
Private IUserID
Private IUserName

Public Property Let AddDate(ByVal Value)
IAddDate = Value
End Property
Public Property Get AddDate()
AddDate = IAddDate
End Property

Public Property Let Content(ByVal Value)
IContent = Value
End Property
Public Property Get Content()
Content = IContent
End Property

Public Property Let Count(ByVal Value)
ICount = Value
End Property
Public Property Get Count()
Count = ICount
End Property

Public Property Let NewsID(ByVal Value)
INewsID = Value
End Property
Public Property Get NewsID()
NewsID = INewsID
End Property

Public Property Let Title(ByVal Value)
ITitle = Value
End Property
Public Property Get Title()
Title = ITitle
End Property

Public Property Let UserID(ByVal Value)
IUserID = Value
End Property
Public Property Get UserID()
UserID = IUserID
End Property

Public Property Let UserName(ByVal Value)
IUserName = Value
End Property
Public Property Get UserName()
UserName = IUserName
End Property

Private Sub Class_initialize()
End Sub
Private Sub Class_Terminate()
End Sub

End Class
%>

  這裡用了類名DataNews,因為VBScript不支持Namespace(-_-),以前綴區分,而類中私有屬性用I作前綴,沒什麼特別含義,僅僅是因為I所占寬度較小,不影響理解時的聯想反應速度,如果非要拉點合理的解釋的話,那麼就是,Private中的I,以區分於Public,不用m_之類,是因為覺得它不夠美觀,影響編碼心情(所以不喜歡寫C),因為需要以優雅之心情,編寫優雅的代碼(哎呀,誰扔的雞蛋?拜托換個新鮮點的)。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved