Use HTML-only universal data management and services

Source: Internet
Author: User

Use HTML-only generic data management and services. However, to collect data, you need a data repository. To avoid many problems caused by using the database server, you can collect the data in XML. The basic structure of our project is as follows:

<User>
<First_name/>
<Last_name/>
<MI/>
</User>

I initially restricted the data to first name, last name, and middle. The basic idea behind this page is that user information is obtained on this page. After the user information requirements are met, the process must be transferred to the next logical collection step. To make things easier, I will package user functions into an ASP class.

Function coalesce (vvar, Valt)
If vval = "" Or vartype (vval) = 1 or vartype (vval) = 0 then
Coalesce = Valt
Else
Coalesce = vval
End if
End Function

Class cuser
Private m_ SQL, m_dom

Public property get Dom ()
Set dom = m_dom
End Property

Public sub saveuser ()
M_ SQL .save "save_user", m_dom
End sub

Public Function validate ()
m_dom.loadxml " " & m_ SQL .validateuser (m_dom) & " "
if not m_dom.selectsinglenode ("// error ") is nothing then
validate = false
else
validate = true
end if
end function

private sub collectdata (DOM, ocollection)
dim nitem, node, parent_node, N, skey
for nitem = 1 to ocollection. count
skey = ocollection. key (nitem)
set parent_node = Dom. selectsinglenode ("//" & skey & "S")
if not parent_node is nothing then
for n = 1 to ocollection (skey ). count
set node = parent_node.selectsinglenode (skey & _
"[String (.) = '"&
ocollection (skey) (n) &"'] ")
If node is nothing then
set node = Dom. createnode (1, skey, "")
set node = parent_node.appendchild (node)
end if
node. TEXT = coalesce (ocollection (skey) (N), "")
next
else
set node = Dom. selectsinglenode ("//" & skey)
if not node is nothing then _
node. TEXT = coalesce (ocollection (skey), "")
end if
next
end sub

Private sub class_initialize ()
Set m_ SQL = new csql
Set m_dom = server. Createobject ("msxml2.domdocument ")
M_dom.async = false
If vartype (Request ("txtuserxml") = 0 or request ("txtuserxml") = "" then
M_dom.loadxml request ("txtuserxml ")
Else
M_dom.load "<root>" & server. mappath ("user. xml") & "</root>"
End if
Collectdata m_dom, request. Form
Collectdata m_dom, request. querystring
End sub

Private sub class_terminate ()
Set m_ SQL = nothing
Set m_dom = nothing
End sub

End Class

Class csql
Private m_dal, m_stream

Public Function save (sstoredproc, Odom)
'Advarchar = 200
M_dal.runsp array (m_dal.mp ("@ xml_param", 200,800 0, Odom. XML ))
End Function

Public Function validateuser (Odom)
Set m_stream = m_dal.runspreturnstream ("validate_user", array (_
M_dal.mp ("@ xml_param", 200,800 0, Odom. XML )))
Validateuser = m_stream.readtext (-1)
M_stream.close
End Function

Private sub class_initialize ()
Set m_dal = server. Createobject ("mypkg. mydal ")
M_dal.getconnection "some connection string"
Set m_stream = server. Createobject ("ADODB. Stream ")
End sub

Private sub class_terminate ()
Set m_dal = nothing
Set m_stream = nothing
End sub

End Class
The csql class is built based on mypkg. mydal, a data access layer (m_dal) component. This component is built based on the Fitch and Mather Dal components, which can be found in msdn. In this way, we can interact with your SQL ServerCodeBuilt bridges.

After the cuser object is initialized, it collects request data and uses the collectdata () sub-function to put the collected data into a corresponding node of userdom. (I will not explain the code because it is quite easy to understand .) After the data is collected (or not collected), we will use XSL to convert the data content into a layout.

<? XML version = "1.0"?>
<XSL: stylesheet xmlns: XSL = http://www.w3.org/1999/XSL/Transform
Version = "1.0">
<XSL: output method = "html"/>

<XSL: template match = "/">
<XSL: If test = "// error">
<Font color = "red"> * Information in red is required <br/> </font>
</XSL: If>
<XSL: Apply-templates select = "// user"/>
</XSL: Template>

<XSL: template match = "user">
<Font>
<XSL: attribute name = "color">
<XSL: Choose>
<XSL: When test = "// error [. = 'first name']"> Red </XSL: When>
<XSL: otherwise> black </XSL: otherwise>
</XSL: Choose>
</XSL: attribute>
First name:
</Font>
<Input type = "text" name = "first_name">
<XSL: attribute name = "value"> <XSL: value-
Select = "first_name"/> </XSL: attribute>
</Input> <br/>
<Font>
<XSL: attribute name = "color">
<XSL: Choose>
<XSL: When test = "// error [. = 'mi']"> Red </XSL: When>
<XSL: otherwise> black </XSL: otherwise>
</XSL: Choose>
</XSL: attribute>
Mi:
</Font>
<Input type = "text" name = "mi">
<XSL: attribute name = "value"> <XSL: value-of select = "mi"/> </XSL: attribute>
</Input> <br/>
<Font>
<XSL: attribute name = "color">
<XSL: Choose>
<XSL: When test = "// error [. = 'last _ name']"> Red </XSL: When>
<XSL: otherwise> black </XSL: otherwise>
</XSL: Choose>
</XSL: attribute>
Last name:
</Font>
<Input type = "text" name = "last_name">
<XSL: attribute name = "value"> <XSL: value-
Select = "last_name"/> </XSL: attribute>
</Input> <br/>
</XSL: Template>

</XSL: stylesheet>

This style sheet converts the content into a layout. The error check is very important. The Stored Procedure checks the data by determining whether the data needs to be processed. An "errors" node is returned for each domain that cannot be empty but has no data filled. The XML output is roughly as follows:

<User>... </user> <errors> <error> first_name </error>... </errors>
This style sheet converts the content into a layout. The error check is very important. The Stored Procedure checks the data by determining whether the data needs to be processed. An "errors" node is returned for each domain that cannot be empty but has no data filled. The XML output is roughly as follows:

<User>... </user> <errors> <error> first_name </error>... </errors>

Note that if an error matches the node name, the output will be red. We need the following ASP to combine all the previous items.

<% @ Language = VBScript %>
<%
Option explicit
dim ouser
set ouser = new cuser
If ouser. validate () Then
set ouser = nothing
server. transfer "nextpage. ASP "
end if
%>



<%
response. write into transform (ouser. dom, "user. XSL ")
%>
value =" <% = ouser. dom. XML %> ">




<%
set ouser = nothing

Function compute transform (VXML, invalid filename)
Dim m_xml, m_xsl
If vartype (VXML) = 8 then
Set m_xml = m_dom
M_xml.loadxml VXML
Elseif vartype (VXML) = 9 then
Set m_xml = VXML
End if
If m_xml.parseerror.errorcode <> 0 then _
Err. Raise vbobjecterror, "xmltransform (...)", m_xml.parseerror.reason
Set m_xsl = server. Createobject ("msxml2.domdocument ")
M_0000.async = false
M_0000.load server. mappath (invalid filename)
If m_xsl.parseerror.errorcode <> 0 then _
Err. Raise vbobjecterror, "xmltransform (...)", m_pai.parseerror.reason
Export transform = m_xml.transformnode (m_xsl)
Set m_xsl = nothing
End Function
%>
<! -- # Include file = "cuser. asp" -->

ASP Code creates a cuser object. If there is data, it fills in the data. Then, use the DOM of cuser to create the result HTML through XSL conversion. The conversion is encapsulated into a function called transform. Remember to store the result cuser Dom to a hidden <input> element. Alternatively, you can store the cuser DOM in a session variable and retrieve it during initialization.

After completing this page, you can create other pages based on the previous skeleton code. Now you have created a copy-and-paste solution for data collection. The best part of this solution is that all the output is pure HTML and does not have any browser-specific properties or style sheets. In addition, because the functions are encapsulated into the class, you can use XSLT to generate a layout, and the code runs quite fast.

--------------------------------------------------------------------------------
Author: Phillip Perkins is the signatory of Ajilon consulting. He has rich experience, from machine control and customer/server to enterprise intranet applications.

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.