XML To Web form/VB Process

Hi All,

i currently have a website which contains a booking form for a application to be sent out.

this form is done in ASP and has the function codes in a joined VB page.

we are going to be receiving the form data from clients in a XML format shortly, what i am trying to do is use the function code/form itself from the website to run the data from the XML against the form, how easy is this to do?

is there anything i can look at that will guide me in order that i can simply repopulate the form with the xml data OR simply run the VB script against the XML?

im a beginner on all of this so any guidance would be highly appreciated.

thanks,

Arran
gaa18Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Here is a couple of examples.  You start out by reading the xml.   In the first example, you can see it is loading index.xml on line 6.   Then starting at the node, index/folders/folder, we start looping through.  If you look at the original question from that link, you can see the xml is posted.   This should give you a good start.

http://www.experts-exchange.com/Programming/Languages/Scripting/ASP/Q_28472298.html#a40185775
<ul>
<%
Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load Server.MapPath("index.xml")
 
Set folder = XMLDom.SelectNodes("index/folders/folder")
 
For Each folderItem In folder
   id =folderItem.SelectSingleNode("id").text
   response.write "<li>"&id
   		response.write "<ul>"
   		for each documentItem in folderItem.SelectNodes("documents/document")
    		response.write "<li>"&documentItem.SelectSingleNode("id").text &"</li>"
   		next
  		response.write "</ul>"
  		response.write "</li>"
Next
 
Set xmlDOM = Nothing
%>
</ul>

Open in new window


http://www.experts-exchange.com/Programming/Languages/Scripting/ASP/Q_28451793.html#a40123064
URL = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
Set objXML = Server.CreateObject("MSXML2.DOMDocument") ' don't add version!  let windows pick it

objXML.setProperty "ServerHTTPRequest", True
objXML.async =  False
objXML.Load(URL)

Set currencyLookup = Server.CreateObject("Scripting.Dictionary")

Set cubes = objXML.getElementsByTagName("Cube")
Response.Write "Found " & cubes.Length & " cubes (not all are cubes with currency)<hr>"
For c = 0 To cubes.Length - 1
    Set cube = cubes.Item(c)
    ' Response.Write cube.xml
    curName = Trim("" & cube.getAttribute("currency") )
    curRate = Trim("" & cube.getAttribute("rate") )
    If curName <> "" AND curRate <> "" Then
        Response.Write "adding " & curName & " :: " & curRate & "<br/>"
        currencyLookup.Add curName, CDBL(curRate)
    End If
Next

' now you can lookup any currency from that dictionary object thus:
gbp = currencyLookup("GBP")

' and you could convert from, say gbp to usd via this:
usd = currencyLookup("USD")

If Not ( IsEmpty(gbp) OR IsEmpty(usd) ) Then
    Response.Write "1.00 GBP is the same as " & FormatNumber( usd / gbp, 2 ) & " USD<br/>"
End If

jpy = CurrencyLookup("JPY")
If Not ( IsEmpty(jpy) OR IsEmpty(usd) ) Then
    Response.Write "1.00 USD is the same as " & FormatNumber( jpy / usd, 2 ) & " JPY<br/>"
End If

Open in new window

0
gaa18Author Commented:
still baffled! :'(

the xml file will contain multiple records that will need to be processed.... all i want to really do is run the XML agains the VB scripts that create the application forms...
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Maybe I am confused as to what you want to do.  I read your question as if you have an xml file like below.
<booking>
      <person>John</person>
      <destination>FL</destination>
      <date>8/1/2014</date>
      <duration>4</duration>
</booking>

Open in new window

And you want to read the xml file like above into your asp/vb code.  That is what the samples I showed you do.

Your looping would come from xml that might look like
<booking>
      <person>John</person>
      <destination>FL</destination>
      <date>8/1/2014</date>
      <duration>4</duration>
</booking>
<booking>
      <person>Mike</person>
      <destination>NY</destination>
      <date>8/15/2014</date>
      <duration>6</duration>
</booking>
<booking>
      <person>Sue</person>
      <destination>CA</destination>
      <date>8/4/2014</date>
      <duration>3</duration>
</booking>

Open in new window

You will notice in the code samples, there are for each statements that loop through each node.  Take a look at the original  question ww.experts-exchange.com/Programming/Languages/Scripting/ASP/Q_28472298.html (2nd code snippet in the question) and you can see the xml we are working with.  The code above http:#a40198739 is what was used to loop through that xml file.  

I hope this makes sense or maybe I have not read your question properly.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

gaa18Author Commented:
the code i am using is a asp form, the problem is i have to use the exact form code, so in essence i need to create a macro that will load the data into the form and simply submit it. this is the problem.

the reason for this is there are amendments made daily to the data that is sent out, so we don't want to replicate on a daily basis the code that is sent out if that makes sense?

thanks,

Arran
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I am still having a hard time following what you are asking.  

>i have to use the exact form code, so in essence i need to create a macro that will load the data into the form

In my example you will see the following response.write
 response.write "<li>"&documentItem.SelectSingleNode("id").text &"</li>"

Open in new window

Instead of writing to the screen, you can save that as a variable.
 
dim theID
theID = documentItem.SelectSingleNode("id").text

Open in new window

Then in your form
<form method="post" action="somepage.asp">
<input name="the_id" value="<%=theID%>">
<button type="submit">submit</button>

Open in new window

Or you can use xmlhttppost to send the data as a post automatically  http://support.microsoft.com/kb/290591 .
DataToSend = "id="&theID
	dim xmlhttp 
	set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
	xmlhttp.Open "POST","http://mysite.com/somepage.asp",false
	xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	xmlhttp.send DataToSend
	Response.ContentType = "text/xml"
	Response.Write xmlhttp.response ' comment this line out if your form page does not send something to the screen
        Set xmlhttp = nothing

Open in new window

0
gaa18Author Commented:
thanks!!! ill show you what i am trying to do, can you let me know if this will work?

this is the xml:
<?xml version="1.0" encoding="UTF-8"?>
<Document>
       <Passenger>
              <Trav_Name>Caroline Aarons</Trav_Name>
              <Pass_No>598746121</Pass_No>
              <Pass_Exp>May-16</Pass_Exp>
              <DoB>27/05/1967</DoB>
              <email>mailing@visaswift.com</email>
              <Nat>United Kingdom</Nat>
              <Destin>China</Destin>
              <Date_Trav>13/08/2014</Date_Trav>
          </Passenger>
       <Passenger>
              <Trav_Name>Mary Anderson</Trav_Name>
              <Pass_No>698126957</Pass_No>
              <Pass_Exp>Jun-21</Pass_Exp>
              <DoB>05/09/1984</DoB>
              <email>mailing@visaswift.com</email>
              <Nat>United Kingdom</Nat>
              <Destin>Russia</Destin>
              <Date_Trav>16/08/2014</Date_Trav>
          </Passenger>
       <Passenger>
              <Trav_Name>Robert Athur</Trav_Name>
              <Pass_No>369512598</Pass_No>
              <Pass_Exp>Sep-19</Pass_Exp>
              <DoB>17/06/1979</DoB>
              <email>mailing@visaswift.com</email>
              <Nat>United Kingdom</Nat>
              <Destin>India</Destin>
              <Date_Trav>25/07/2014</Date_Trav>
          </Passenger>
       <Passenger>
              <Trav_Name>Guy Fisher</Trav_Name>
              <Pass_No>554842368</Pass_No>
              <Pass_Exp>Jan-17</Pass_Exp>
              <DoB>04/08/1992</DoB>
              <email>mailing@visaswift.com</email>
              <Nat>United Kingdom</Nat>
              <Destin>Nigeria</Destin>
              <Date_Trav>15/07/2014</Date_Trav>
          </Passenger>
       <Passenger>
              <Trav_Name>Julie Feld</Trav_Name>
              <Pass_No>554788628</Pass_No>
              <Pass_Exp>May-15</Pass_Exp>
              <DoB>16/11/1974</DoB>
              <email>mailing@visaswift.com</email>
              <Nat>United Kingdom</Nat>
              <Destin>Saudi Arabia</Destin>
              <Date_Trav>24/07/2014</Date_Trav>
          </Passenger>
   </Document>

Open in new window


i have sorted the VB side and this is the form send that i am trying to configure:
<script type="text/javascript">                
function senddata() {

// Check Entry
if($('#destination :selected').val()==""||$('#typeoftravel :selected').val()==""||$('#nationality :selected').val()==""||$('#contactname').val()==""||$('#phonenumber').val()==""||$('#emailaddress').val()==""||$('#agreeterms').is(':checked')==false) {
alert("Required information is missing");
return;
} 

$.ajax({url:"http://www.mysite.com/visaservice/service.asmx/emailvisapack?destination="+$('#destination :selected').val()+"&typeoftravel="+$('#typeoftravel :selected').val()+"&nationality="+$('#nationality :selected').val()+"&name="+$('#contactname').val()+"&phonenumber="+$('#phonenumber').val()+"&emailaddress="+$('#emailaddress').val()+"",dataType:'xml',success:function(result){
	alert("Thank you for your request. \n Your visa pack has been sent and one of our consultants will be in touch shortly."); // Popup Thanking User
	$.mobile.changePage( "#our_intro", { transition: "slide"}); // You could change this to go to a seperate page with thank you message
}});
}
</script>

Open in new window


what would i need to do so that i could load all the individual passenger information from the one file and process them individually? also if there are more then 1 file present?
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Are you trying to do this in jquery or vbscript?
0
gaa18Author Commented:
if i can use the existing Jquery script that would be easier i think?
0
gaa18Author Commented:
whichever is easier in fairness, I've gotta sort something asap :(
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
I'm going to step in and offer my two cents worth. I know Scott (lately) has been unavailable around this time of day....

what would i need to do so that i could load all the individual passenger information from the one file and process them individually? also if there are more then 1 file present?

does the info from the file have a chance to change, is that why you want to load it in the form? otherwise, why not load all of the records directly into the database?

i'll get you some client side code in a few that shows how to populate a form, just wanted to throw this out there first
0
gaa18Author Commented:
yeah it will be changing all the time, a client will be dumping these files on our server periodically, i need a process to pick them up process them and delete them....
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
so the example below is based off of jQuery's parseXML function, it loads the data via ajax and then parses the data into the form:

//-- using the javascript you posted above, it would look something like this
<script type="text/javascript">                
function senddata() {

// Check Entry
if($('#destination :selected').val()==""||$('#typeoftravel :selected').val()==""||$('#nationality :selected').val()==""||$('#contactname').val()==""||$('#phonenumber').val()==""||$('#emailaddress').val()==""||$('#agreeterms').is(':checked')==false) {
alert("Required information is missing");
return;
} 

$.ajax({
	url:"http://www.mysite.com/visaservice/service.asmx/emailvisapack",
	data: { "destination"  :   $('#destination :selected').val(),
			"typeoftravel" :   $('#typeoftravel :selected').val(),
			"nationality"  :   $('#nationality :selected').val(), 
			"name"         :   $('#contactname').val(),
			"phonenumber"  :   $('#phonenumber').val(), 
			"emailaddress" :   $('#emailaddress').val()
		  }
	dataType:'xml',
	success:function(result){
		var xmlDoc = $.parseXML( xml ), $xml = $( xmlDoc );	
		$($xml).each(function(){
		   alert("Trav_Name = " & $(this).find("Passenger[Trav_Name]").text());
		   alert("Pass_No = " & $(this).find("Passenger[Pass_No]").text());
		   alert("Trav Name = " & $(this).find("Passenger[Pass_Exp]").text());
		 });		
		 
		 alert("Thank you for your request. \n Your visa pack has been sent and one of our consultants will be in touch shortly."); 
		// Popup Thanking User
		$.mobile.changePage( "#our_intro", { transition: "slide"}); // You could change this to go to a seperate page with thank you message
	}
	});
}
</script>

Open in new window


this is untested but I'm confident that it's very close to what you need. I formatted it for readability, and also changed your ajax call to use the data parameter instead of one long url string, just easier to read. If everything is working properly, you should see 3 alerts pop up with the correct values. once you're happy with that, go ahead and change the alerts to either variables that get populated or insert the values into the form directly (let us know if you need help with that).

here's also a working generic example from which I based off of the solution above. I found this example on a competing site, thus why it's not a direct link, but credit should go to a Jens Roland from StackOverflow

var xml='<Pages>
          <Page Name="test">
           <controls>
              <test>this is a test.</test>
           </controls>  
          </Page>
          <page Name = "User">
           <controls>
             <name>Sunil</name>
           </controls>
          </page>
        </Pages>';
		
xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc );
    $($xml).each(function(){
       alert($(this).find("Page[Name]>controls>name").text());
     });

Open in new window


jfiddle - http://jsfiddle.net/R37mC/1/
0
gaa18Author Commented:
thanks so much! where is the XML Defined on the example?

thanks,

Arran
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
in the example, it's defined on line 1, as a string of XML. In the code I wrote using your data, the xml is coming from the ajax call to the URL
0
gaa18Author Commented:
ahhh that url is where the data submits to though......
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
where is the xml coming from in your example then?
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
just as a test, try throwing your xml into a variable (like the example) and see if that gets you what you want. From there, we can work on incorporating the xml doc(s) you'll be working with
0
gaa18Author Commented:
nothings happening :( not working for love nor money.
essentially all i am trying to do in basic terms is:
client sends us an xml with passenger information:

we run a script to import this xml and use the above script to map the fields and submit, it moves on to the next passenger and submits and so on.... once completed it renames/moves/deletes the XML file.

I'm really really stuck on this one :'(
0
gaa18Author Commented:
if you look at: http://www.visaswift.com/test.html you will see the error i am facing.....
0
gaa18Author Commented:
seem to have made some progress however it is not loading in the XML it just gives the message required info is missing although it is not?
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
See if this helps http://jsbin.com/likew/1

var xml = "<Document> <Passenger> <Trav_Name>Caroline Aarons</Trav_Name> <Pass_No>598746121</Pass_No> <Pass_Exp>May-16</Pass_Exp> <DoB>27/05/1967</DoB> <email>mailing@visaswift.com</email> <Nat>United Kingdom</Nat> <Destin>China</Destin> <Date_Trav>13/08/2014</Date_Trav> </Passenger> <Passenger> <Trav_Name>Mary Anderson</Trav_Name> <Pass_No>698126957</Pass_No> <Pass_Exp>Jun-21</Pass_Exp> <DoB>05/09/1984</DoB> <email>mailing@visaswift.com</email> <Nat>United Kingdom</Nat> <Destin>Russia</Destin> <Date_Trav>16/08/2014</Date_Trav> </Passenger> <Passenger> <Trav_Name>Robert Athur</Trav_Name> <Pass_No>369512598</Pass_No> <Pass_Exp>Sep-19</Pass_Exp> <DoB>17/06/1979</DoB> <email>mailing@visaswift.com</email> <Nat>United Kingdom</Nat> <Destin>India</Destin> <Date_Trav>25/07/2014</Date_Trav> </Passenger> <Passenger> <Trav_Name>Guy Fisher</Trav_Name> <Pass_No>554842368</Pass_No> <Pass_Exp>Jan-17</Pass_Exp> <DoB>04/08/1992</DoB> <email>mailing@visaswift.com</email> <Nat>United Kingdom</Nat> <Destin>Nigeria</Destin> <Date_Trav>15/07/2014</Date_Trav> </Passenger> <Passenger> <Trav_Name>Julie Feld</Trav_Name> <Pass_No>554788628</Pass_No> <Pass_Exp>May-15</Pass_Exp> <DoB>16/11/1974</DoB> <email>mailing@visaswift.com</email> <Nat>United Kingdom</Nat> <Destin>Saudi Arabia</Destin> <Date_Trav>24/07/2014</Date_Trav> </Passenger> </Document>",
  xmlDoc = $.parseXML( xml );


 
$('Passenger', xml).each(function(i){
   var Trav_Name =  $(this).find("Trav_Name").text();
   var  Pass_No =  $(this).find("Pass_No").text();
    var Pass_Exp =  $(this).find("Pass_Exp").text();

  $( "#myData" ).append( '<h2>'+Trav_Name+'</h2><ul><li>No:'+Pass_No+' </li><li>exp:'+Pass_Exp+'</li></ul>' );
});

Open in new window

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>padas</title>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<div id="myData"></div>

</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
on your test page, you need to comment out the following javascript:

if($('#destination :selected').val()==""||$('#typeoftravel :selected').val()==""||$('#nationality :selected').val()==""||$('#contactname').val()==""||$('#emailaddress').val()==""||$('#agreeterms').is(':checked')==false) {
alert("Required information is missing");
return;
}

none of those fields exist on your page, so they will always return false
0
gaa18Author Commented:
done and now get this:

ReferenceError: Can't find variable: xml
      success (test.html, line 45)
      l (jquery-1.8.3.min.js, line 2)
      fireWith (jquery-1.8.3.min.js, line 2)
      T (jquery-1.8.3.min.js, line 2)
      r (jquery-1.8.3.min.js, line 2)
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
change

success:function(result){

to

success:function(xml){
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
if you still get errors after that, let me know and post the latest version of your code and I'll see if I can get it working on my end first
0
gaa18Author Commented:
nope still nada:

<script type="text/javascript">                
function tryme(){

// Check Entry

$.ajax({
 url:"test.xml",
 data: { "destination"  :   $('#destination :selected').val(),
   "typeoftravel" :   $('#typeoftravel :selected').val(),
   "nationality"  :   $('#nationality :selected').val(), 
   "name"         :   $('#contactname').val(),
   "phonenumber"  :   $('#phonenumber').val(), 
   "emailaddress" :   $('#emailaddress').val()
    },
 
 dataType:'xml',
 success:function(XML){
  var xmlDoc = $.parseXML( xml ), $xml = $( xmlDoc ); 
  $($xml).each(function(){
     alert("Trav_Name = " & $(this).find("Passenger[Trav_Name]").text());
     alert("Pass_No = " & $(this).find("Passenger[Pass_No]").text());
     alert("Trav Name = " & $(this).find("Passenger[Pass_Exp]").text());
   });  
   
   alert("Thank you for your request. \n Your visa pack has been sent and one of our consultants will be in touch shortly."); 
  // Popup Thanking User
  $.mobile.changePage( "#our_intro", { transition: "slide"}); // You could change this to go to a seperate page with thank you message
 }
 });
}
</script>

Open in new window

0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
can you post the code for the entire page? i want to put it in a page on my server and tinker :)
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
>jquery-1.8.3.min.js

time to upgrade.  Use jquery 1.1x if you want to support older IE or 2.x if you want a lighter weight jquery that does not support older IE.  http://jquery.com/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.