还有一个读取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),因为需要以优雅之心情,编写优雅的代码(哎呀,谁扔的鸡蛋?拜托换个新鲜点的)。
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/webkaifa/)