The definition and processing of data object in ASP non-database implementation

Source: Internet
Author: User
Tags definition bool count include reference xpath root directory
Objects | data | database

Say non-database way, some Toda, but in the absence of a database, but also to give a good opportunity to exercise, not to mention I have nothing on the whole database to play the way is abhorrence, sometimes, in the limited resources and simple function, the use of file management itself can be a good implementation of a system, Why not use the database?
OK, employed ASP program, the main reason for ASP program is the expansion of COM object, so after a brainstorm, a set of boxing: Scripting.FileSystemObject, Scripting.Dictionary and MSXML2 . domdocument.4.0.
The following is a file management program as an example, the implementation of a brief description:

First, it is the idea.

1. The managed data object is a file object, and the file object can correspond to a node in the XML

2. The structure of the file object can be defined by itself

3. File object Additions, deletions, modifications, and inquiries

In XML, it is easy to make full use of Xpath to realize query, so the problem should be summed up as the problem of XML node's deletion and modification, and the definition of object structure. Needless to say, the key is the customization of the structure of the object (which is the declaration of the class in the object-oriented).

Next, is the implementation.

One is the structure file

The structure includes: English name, Chinese display name, type, display template (or reference), default value, etc.

In fact, the schema-like things, and then save these structures in a file, many operations can be automatically processed in the loop, such as displaying a file, you can follow this structure to display all the property fields.

The following is a demonstration of a structural document Documentx.dna:

*/docs= file

*/docs/@VERSION = version%%string%%[num]. [NUM]. [NUM]. [num]%% 1.0.0 0

*/docs/doc= file

+/docs/doc/@ID = Identity%%string%%%%=uniqueid ()

+/docs/doc/@HOT = Popular%%num%%%%0

/docs/doc/title= Title

/docs/doc/departfrom= Communications Unit%%dictionary%%department%%

/docs/doc/@DONE = is the process complete%%bool%%%%

What needs to be explained is that the English name is in an Xpath way to facilitate XML processing.

The English name is indicated as a system field and also a property field of a non-file object.

The English name Plus + indicates that the field is read-only for the user and the value is specified by the system.

In addition to the former plus * or plus + number, there are also prevent the deletion of the reason, because the * or + number is not displayed to the user.

Use the = number to separate the English name from the other parts, while the other parts are separated by percent, followed by the Chinese display name, the item type, which displays the template (or reference), the default value.

Need to explain the type, if the type is DICTIONARY, the display template (or reference) or reference for the specific DICTIONARY file, DICTIONARY save form, in the form of the tstringlist in Delphi, with the = number of keywords and values separated :

cs1= Test Unit 1

cs2= Test Unit 2

The second is to use a new file to show the problem

Look at the demo file first:

<% @LANGUAGE =vbscript%>
<%
Dim SKey, svalue, Sign, Pos, Attrid, Values, F, FName, Count
%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<meta http-equiv= "Content-language" content= "ZH-CN"
<body>
<form method= "POST" action= "documents! Save.asp ">
<table border= "0" width= "100%" cellpadding= "0" style= "border-collapse:collapse"
<tr>
&LT;TD bgcolor= "#C 0C 0C 0" ><b> new </b></td>
</tr>
<tr>
<td>
<table border= "1" width= "100%" cellspacing= "0" cellpadding= "0" style= "Border-collapse:collapse" bordercolor= "# 000000 ">
<tr>
&LT;TD width= "10%" > </td>
<td> value </td>
</tr>
<%
' Count = 0
' Documentx for Scripting.Dictionary object, for Documentx.dna content
For each sKey in Documentx
Sign = Left (SKey, 1)
If sign<> "*" Then
svalue = Documentx. Item (SKey)
Values = Split (svalue & "%%%%%%", "%")
Pos = InStrRev (SKey, "/")
Attrid = Right (SKey, Len (SKey)-Pos)
If Left (attrid,1) = "@" Then
Attrid = Mid (Attrid, 2) & "_inline" means @ is generally a built-in property
End If
Attrid = "Attr_" & Attrid
%>
<tr>
&LT;TD width= "10%" ><%=values (0)%></td>
<td>
<%
If sign= "+" Then ' if read-only property
%>
<input type= "hidden" name= "<%=attrid%>" value= ""/> system Calculation: <%=values (3)%>
<%
Else
' Display according to type
If Values (1) = "BOOL" Then
Response.Write "<input type=" "checkbox" "Name=" "& Attrid &" "Value=" "1" "/>"
Else
If Values (1) = "DICTIONARY" Then
' Environment as Scripting.Dictionary object
' Environment. The root directory that the program manages is stored in Item ("root")
FName = environment. Item ("ROOT") & "\dictionary\" & Values (2) & ". DiC"
%>
<select name= "<%=attrid%>"
<%
If FSO. FileExists (FName) Then
Set F = FSO. OpenTextFile (FName, 1, False)
Do as not F.atendofstream
svalue = F.readline
Pos = InStr (svalue, "=")
If pos>0 Then
Response.Write "<option value=" "& Left (svalue, Pos-1) &" ">" & Right (svalue, Len (svalue)-pos) & " ;/option> "
End If
Loop
F.close
End If
%>
</select>
<%
Else
Response.Write "<input type=" "TextBox" "Name=" "& Attrid &" "size=" "30" "/>"
End If
End If
End If
%>
</td>
</tr>
<%
' Count = Count + 1
End If
Next
%>
<tr>
&LT;TD width= "10%" > </td>
<td> </td>
</tr>
<tr>
&LT;TD width= "10%" > </td>
<td> </td>
</tr>
</table>
</td>
</tr>
<tr>
&LT;TD bgcolor= "#C 0C 0C 0" align= "right" valign= "middle" ><input type= "Submit" Name= "Btnsave" value= "Save"/> <input Type= "button" Name= "Btnreset" value= "heavy Loss"/></td>
</tr>
</table>
</form>
</body>

The third is to use code to explain the implementation of XML storage
<% @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 I



Related Article

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.