logo
Previous Thread
Next Thread
Print Thread
Joined: Sep 2006
Posts: 1
K
Newbie
OP Offline
Newbie
K
Joined: Sep 2006
Posts: 1
Hello,everyone!
First...excuse me for a bad english <img src="/images/graemlins/blush.gif" alt="" />
Well....i am absolute beginner in ASP and programming <img src="/images/graemlins/frown.gif" alt="" />
I use example html forms:
<html><body>
<form action="saveForm.asp" method="post">
<p><b>Enter your contact information</b></p>
First Name: <input type="text" id="fname" name="fname"><br />
Last Name: <input type="text" id="lname" name="lname"><br />
Country: <input type="text" id="country" name="country"><br />
Email: <input type="text" id="email" name="email"><br />
<input type="submit" id="btn_sub" name="btn_sub" value="Submit">
<input type="reset" id="btn_res" name="btn_res" value="Reset">
</form>
</body></html>

asp file is:
<%
dim xmlDoc
dim rootEl,fieldName,fieldValue,attID
dim p,i'Do not stop if an error occurs
On Error Resume NextSet xmlDoc = server.CreateObject("Microsoft.XMLDOM")
xmlDoc.preserveWhiteSpace=true'Create a root element and append it to the document
Set rootEl = xmlDoc.createElement("customer")
xmlDoc.appendChild rootEl'Loop through the form collection
for i = 1 To Request.Form.Count
'Eliminate button elements in the form
if instr(1,Request.Form.Key(i),"btn_")=0 then
'Create a field and a value element, and an id attribute
Set fieldName = xmlDoc.createElement("field")
Set fieldValue = xmlDoc.createElement("value")
Set attID = xmlDoc.createAttribute("id")
'Set the value of the id attribute equal to the name of
'the current form field
attID.Text = Request.Form.Key(i)
'Append the id attribute to the field element
fieldName.setAttributeNode attID
'Set the value of the value element equal to
'the value of the current form field
fieldValue.Text = Request.Form(i)
'Append the field element as a child of the root element
rootEl.appendChild fieldName
'Append the value element as a child of the field element
fieldName.appendChild fieldValue
end if
next'Add an XML processing instruction
'and insert it before the root element
Set p = xmlDoc.createProcessingInstruction("xml","version='1.0'")
xmlDoc.insertBefore p,xmlDoc.childNodes(0)'Save the XML file
xmlDoc.save "c:\Customer.xml"'Release all object references
set xmlDoc=nothing
set rootEl=nothing
set fieldName=nothing
set fieldValue=nothing
set attID=nothing
set p=nothing'Test to see if an error occurred
if err.number<>0 then
response.write("Error: No information saved.")
else
response.write("Your information has been saved.")
end if
%>
and result:
<?xml version="1.0" ?>
<customer>
<field id="firstName">
<value>Hege</value>
</field>
<field id="lastName">
<value>Refsnes</value>
</field>
<field id="country">
<value>Norway</value>
</field>
<field id="email">
<value>mymail@myaddress.com</value>
</field>
</customer>

My question is how is disspose the asp code for this result:
<?xml version="1.0" ?>
<customer>
<firstName>
Hege
</firstName>
<lastName>
Refsnes
</lastName>
<country>
Norway
</country>
<email>
mymail@myaddress.com
</email>
</customer>

Help me,please:(
Best regards!

Sponsored Post Advertisement
Joined: Sep 2006
Posts: 7
BellaOnline Editor
Newbie
Offline
BellaOnline Editor
Newbie
Joined: Sep 2006
Posts: 7
Try this:

<%
dim xmlDoc
dim rootEl,fieldName,fieldValue,attID
dim p,i'Do not stop if an error occurs
'On Error Resume Next
Set xmlDoc = server.CreateObject("Microsoft.XMLDOM")
xmlDoc.preserveWhiteSpace=true 'Create a root element and append it to the document
Set rootEl = xmlDoc.createElement("customer")
xmlDoc.appendChild rootEl'Loop through the form collection

'Create the fields and values
Set fieldName = xmlDoc.createElement("firstName")
Set fieldName2 = xmlDoc.createElement("lastName")
Set fieldName3 = xmlDoc.createElement("country")
Set fieldName4 = xmlDoc.createElement("email")

'Set the value of the value element equal to
'the value of the current form field
fieldName.Text = "Christopher" 'Replace with your request.form("FirstName")
fieldName2.Text = "Combs" 'Replace with your request.form("LastName")
fieldName3.Text = "USA" 'Replace with your request.form("country")
fieldName4.Text = "asp@bellaonline.com" 'Replace with your request.form("email")

'Append the field element as a child of the root element
rootEl.appendChild fieldName
rootEl.appendChild fieldName2
rootEl.appendChild fieldName3
rootEl.appendChild fieldName4

'Add an XML processing instruction
'and insert it before the root element
Set p = xmlDoc.createProcessingInstruction("xml","version='1.0'")
xmlDoc.insertBefore p,xmlDoc.childNodes(0)'Save the XML file

'Save The XML File and release all object references
xmlDoc.save "c:\Customer.xml"
set xmlDoc=nothing
set rootEl=nothing
set fieldName=nothing
set fieldName2=nothing
set fieldName3=nothing
set fieldName4=nothing

'Test to see if an error occurred, if no error, write success.
set p=nothing
if err.number<>0 then
response.write("Error: No information saved.")
else
response.write("Your information has been saved.")
end if
%>


Christopher Combs
ASP @ BellaOnline.com
Moderator for ASP @ BellaOnline

Moderated by  Lisa LowCarb 

Link Copied to Clipboard
Brand New Posts
Astro Women - Birthdays
by Mona - Astronomy - 04/24/24 03:37 PM
2024 - on this day in the past ...
by Mona - Astronomy - 04/24/24 03:33 PM
Check Out My New Website Selective Focus
by Angela - Drama Movies - 04/24/24 01:47 PM
Psalm for the day
by Angie - 04/23/24 04:45 PM
Inspiration Quote
by Angie - 04/23/24 04:43 PM
Sew a Garden Flag
by Cheryl - Sewing Editor - 04/17/24 01:24 PM
Review - Notion for Pattern Designers: Plan, Organ
by Digital Art and Animation - 04/17/24 12:35 AM
Review - Create a Portfolio with Adobe Indesign
by Digital Art and Animation - 04/17/24 12:32 AM
Useful Sewing Tips
by Cheryl - Sewing Editor - 04/10/24 04:55 PM
"Leave Me Alone" New Greta Garbo Documentary
by Angela - Drama Movies - 04/09/24 07:07 PM
Sponsor
Safety
We take forum safety very seriously here at BellaOnline. Please be sure to read through our Forum Guidelines. Let us know if you have any questions or comments!
Privacy
This forum uses cookies to ensure smooth navigation from page to page of a thread. If you choose to register and provide your email, that email is solely used to get your password to you and updates on any topics you choose to watch. Nothing else. Ask with any questions!


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2022 Minerva WebWorks LLC. All rights reserved.


Powered by UBB.threads™ PHP Forum Software 7.7.5