|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
帮助用户快速实现各种应用服务,ASP商有整合各方面资源的能力,可在短期内为用户提供所需的解决方案。例如,典型的ERP安装,如果要在客户端安装的话需要半年到二年的时间,但是美国的一些ASP商如USI和CORIO能在90—120天内提供ERP应用方案。文档被存档以后,假如你再翻开这个文档,那末则会以以下代码列表情势呈现:
MyXMLDoc.xml:
<?xmlversion="1.0"?>
<rootElement>
<childElement1/>
<childElement2/>
</rootElement>
在"MyXMLDoc.xml"文档中,childElement1和childElement2会以空的elements情势呈现。假如它们被赋值,那末每
个值都将由标志符括起来。
如今,让我们来思索一下怎样将HTML数据写到XML文档中往。我们已晓得该怎样创立和存储XML文档。将一个表双数
据写到XML文档中往的历程,如今已演化成为RequestObject"sFormCollection和将每个表单域的value书定到XML
elementvalue中往的步骤反复。以上能够经由过程ASP来完成。
例:将数据保送到XML
如今,我们举一个一般的HTML表单的例子来讲明。此Form有效户名,地点,德律风,和E-MAIL等几个域。并将这些信
息写进XML文件中并保留。
EnterContact.html:
<html>
<head>
<title>
ContactInformation
</title>
</head>
<body>
<formaction="processForm.asp"method="post">
<h3>请输出你的接洽体例</h3>
FirstName:<inputtype="text"id="firstName"name="firstName"><br>
LastName:<inputtype="text"id="lastName"name="lastName"><br>
Address#1:<inputtype="text"id="address1"name="address1"><br>
Address#2:<inputtype="text"id="address2"name="address2"><br>
PhoneNumber:<inputtype="text"id="phone"name="phone"><br>
E-Mail:<inputtype="text"id="email"name="email"><br>
<inputtype="submit"id="btnSub"name="btnSub"value="Submit"><br>
</form>
</body>
</html>
将Form中数据发送到processForm.asp.。这是一个ASP页面,在这个ASP中将重复挪用统一个函数将form数据写进XML
文件。
processForm.asp:
<%
"--------------------------------------------------------------------
"The"ConvertFormtoXML"Functionacceptstoparameters.
"strXMLFilePath-ThephysicalpathwheretheXMLfilewillbesaved.
"strFileName-ThenameoftheXMLfilethatwillbesaved.
"--------------------------------------------------------------------
FunctionConvertFormtoXML(strXMLFilePath,strFileName)
"Declarelocalvariables.
DimobjDom
DimobjRoot
DimobjField
DimobjFieldValue
DimobjattID
DimobjattTabOrder
DimobjPI
Dimx
"InstantiatetheMicrosoftXMLDOM.
SetobjDom=server.CreateObject("Microsoft.XMLDOM")
objDom.preserveWhiteSpace=True
"CreateyourrootelementandappendittotheXMLdocument.
SetobjRoot=objDom.createElement("contact")
objDom.appendChildobjRoot
"IteratethroughtheFormCollectionoftheRequestObject.
Forx=1ToRequest.Form.Count
"Checktoseeif"btn"isinthenameoftheformelement.
"Ifitis,thenitisabuttonandwedonotwanttoaddit
"totheXMLdocument.
Ifinstr(1,Request.Form.Key(x),"btn")=0Then
"Createanelement,"field".
SetobjField=objDom.createElement("field")
"Createanattribute,"id".
SetobjattID=objDom.createAttribute("id")
"Setthevalueoftheidattributeequalthethenameof
"thecurrentformfield.
objattID.Text=Request.Form.Key(x)
"ThesetAttributeNodemethodwillappendtheidattribute
"tothefieldelement.
objField.setAttributeNodeobjattID
"Createanotherattribute,"taborder".Thisjustordersthe
"elements.
SetobjattTabOrder=objDom.createAttribute("taborder")
"Setthevalueofthetaborderattribute.
objattTabOrder.Text=x
"Appendthetaborderattributetothefieldelement.
objField.setAttributeNodeobjattTabOrder
"Createanewelement,"field_value".
SetobjFieldValue=objDom.createElement("field_value")
"Setthevalueofthefield_valueelementequalto
"thevalueofthecurrentfieldintheFormCollection.
objFieldValue.Text=Request.Form(x)
"Appendthefieldelementasachildoftherootelement.
objRoot.appendChildobjField
"Appendthefield_valueelementasachildofthefieldelemnt.
objField.appendChildobjFieldValue
EndIf
Next
"Createthexmlprocessinginstruction.
SetobjPI=objDom.createProcessingInstruction("xml","version="1.0"")
"AppendtheprocessinginstructiontotheXMLdocument.
objDom.insertBeforeobjPI,objDom.childNodes(0)
"SavetheXMLdocument.
objDom.savestrXMLFilePath&""&strFileName
"Releaseallofyourobjectreferences.
SetobjDom=Nothing
SetobjRoot=Nothing
SetobjField=Nothing
SetobjFieldValue=Nothing
SetobjattID=Nothing
SetobjattTabOrder=Nothing
SetobjPI=Nothing
EndFunction
"Donotbreakonanerror.
OnErrorResumeNext
"CalltheConvertFormtoXMLfunction,passinginthephysicalpathto
"savethefiletoandthenamethatyouwishtouseforthefile.
ConvertFormtoXML"c:","Contact.xml"
"Testtoseeifanerroroccurred,ifso,lettheuserknow.
"Otherwise,telltheuserthattheoperationwassuccessful.
Iferr.number0then
Response.write("Errorsoccurredwhilesavingyourformsubmission.")
Else
Response.write("Yourformsubmissionhasbeensaved.")
EndIf
%>
缺乏可以共同遵循的行业标准,ASP还处在发展初期,大家对它的理解不同,如产品和服务标准,收费标准等,不利于行业的健康发展。 |
|