A simple XML-based online staff statistics class

Source: Internet
Author: User
Tags xsl

Class Online
Sub UserState (ustate)
Dim userip,xmldoc,root,newuser,delnode,otime
Otime=day (now ()) *24*60+hour (now ()) *60+minute (now ())
Set xmldoc = Server.CreateObject ("Msxml2.domdocument")
Xmldoc.async = False
Xmldoc.load (Server.MapPath (XmlUrl & "Online.xml"))
Set Root=xmldoc.selectnodes ("//online/at[@oSessionID = '" & Session.SessionID & "' or @oUname = '" & Mycname & "' or ouip= '" & Userip & "']"
If Root.length=0 Then
Set Newuser=xmldoc.createelement ("at")
XmlDoc.documentElement.appendChild (NewUser)
Newuser.setattribute "Osessionid", Session.SessionID
Newuser.setattribute "Ouname", Mycname
Newuser.setattribute "Outype", Myutype
Newuser.setattribute "Oustate", ustate
Newuser.setattribute "Ouip", Userip
Newuser.setattribute "Ouactivetime", Otime
Set newuser=nothing
Else
Root.item (0). Attributes.item (0). Value=session.sessionid
Root.item (0). Attributes.item (1). Value=mycname
Root.item (0). Attributes.item (2). Value=myutype
Root.item (0). Attributes.item (3). value=ustate
Root.item (0). Attributes.item (4). Value=userip
Root.item (0). Attributes.item (5). Value=now ()
End If
Set Delnode=xmldoc.documentelement.selectsinglenode ("//online/at[@oUactiveTime <" "& Otime + &" '] ")
Root.reomvechild (Delnode)
Set delnode=nothing
Set root=nothing
Xmldoc.save (Server.MapPath (XmlUrl & "Online.xml"))
End Sub

Sub Onlinecount ()
Dim Uonline,gonline,root,xmldoc
Set xmldoc = Server.CreateObject ("Msxml2.domdocument")
Xmldoc.async = False
Xmldoc.load (Server.MapPath (XmlUrl & "Online.xml"))
Set Root=xmldoc.selectnodes ("//online/at[@oUtype = ' 1 ']")
Uonline=root.length
Set Root=xmldoc.selectnodes ("//online/at[@oUtype = ' 0 ']")
Gonline=root.length
Set root=nothing
Set xmldoc=nothing
Response.Write "Online:" & Gonline+uonline & "Member:" & Uonline & "Visitors:" & Gonline
End Sub

function Xchar (str)
Xchar=str
Xchar=replace (Xchar, "" "", "" ")
Xchar=replace (Xchar, "" "", "")
Xchar=replace (Xchar, "<", "<")
Xchar=replace (Xchar, ">", ">")
Xchar=replace (Xchar, "&", "&")
End Function
End Class

Although this code is simple but has been covered with xmldom creation, save, node additions, deletions, node property settings, Dom using XSL for simple queries, and so on.

In the online number of more sites, it is recommended to use XSL index, otherwise the speed is unimaginable.

In this paper, Otime record the user's last activity time, because the date of the XML data processing is more complex, such as to use dtd,xsl and so on to code writing and user use caused the same, so here it converts it to digital type.

The online statistics are taken by the length of the selected document, but you can also use the XSL count function directly.

Xchar is an XML special character processing function, which is not prefixed with character processing and is used when used in character-type data processing. Of course, if you are very familiar with DTDs and so on, you can use this function to control the document.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.