Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with XML 1

Status
Not open for further replies.

Remulon

Programmer
Apr 30, 2004
11
AU
I am trying to write the code for an HTML page (or should I say HTML form), that is to (upon submission) create an XML document and post that document to an asp page.

I have no control over the asp page, nor the server machine that it is on. (How much difference does this make?)

Basically I am trying to integrate my website with my dispatch warehouse and all I have from them is the format that the XML file is to be in (ie: element tags and order etc.), and the URL of the asp page.

I understand what XML is and what it is used for, and I have been reading lots of information about both it and asp, but I have seen no examples where any of this is explained.

Any help will be greatly appreciated.
 
Use the File System Object and create the file from that. Here is an example of what I would do. Of course your data might be different, but I am just using this as an example.

'collect all form variables
strFname = request.querystring("firstname")
strLname = request.querystring("lasstname")
strAddress1 = request.querystring("address1")
strAddress2 = request.querystring("address2")
strAddress3 = request.querystring("address3")
strCity = request.querystring("city")
strState = request.querystring("state")
strZip = request.querystring("zip")

'Create FSO Objects
dim objFso, xmlFile
set objFso = server.createobject("Scripting.FileSystemObject")
'create the xml file
set xmlFile = objFso.CreateTextFile("filename.xml")

'start writing our xml to the file we just created.
xmlFile.Write("<xml version='1.0' ?>")
'our xml needs a parent node
xmlFile.Write("<WarehouseFormDate>")
'start out children nodes
xmlFile.Write("<FIRST_NAME>"&strFname&"</FIRST_NAME>")
xmlFile.Write("<LAST_NAME>"&strLname&"</LAST_NAME>")
xmlFile.Write("<ADDRESS1>"&strAddress1&"</ADDRESS1>")
xmlFile.Write("<ADDRESS2>"&strAddress2&"</ADDRESS2>")
xmlFile.Write("<ADDRESS3>"&strAddress3&"</ADDRESS3>")
xmlFile.Write("<CITY>"&strCity&"</CITY>")
xmlFile.Write("<STATE>"&strState&"</STATE>")
xmlFile.Write("<ZIP>"&strZip&"</ZIP>")
'close our parent node
xmlFile.Write("</WarehouseFormDate>")
'close file
xmlFile.Close()
'destroy FSO objects
Set objFso = Nothing


Hope this helps,
Ralph
 
Let me see if I have this corrcet:
You have a form (we'll call this page 1). This form collects the information and send it to another ASP page (page2)
Page2 receives the submitted informaiton and needs to create an xml document that will then be sent to (page3)
Page3 resides elsewhere, I guess in the warehouse system, and is expcting an XML submission (which it probably then parses in it's own form, etc).

If this is correct, then my suggestion would be to build the XML in page2 as string, then use the XMLHTTP object to post that string to Page3's address. This way you won't have a bunch of files building up on your system that have to be deleted, etc. The string is pretty easy to build, just keep concatenating the tags and data. Then to send it you would just post to the remote submission page and send the XML string.

If you need more info on XMLHTTP there have been severakl posts lately aboutit and you should be able to find more from the sarch link above. For anything specific feel free to ask back, especially if I was off base with my attempted translation :p

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
OK.. I'll give you a better definition to my problem:

My warehouse has informed me that we can integrate our ordering system if I post the order form (in XML format) to their asp page (call this page 1).

So I have attempted to create an html page (which is really XHTML I think) that takes the inputted details and makes an xml string (call this page 2).

So at the moment, there are only two pages, my html page(2) and the warehouse's asp page(1).

In my page(2), I post the xml string to the warehouse's page(1). But as you can see, I'm having problems.

--------------------------------------
Questions:
-- Should I be using more than one page to do this?

-- If I wasn't using XHTML, could I do this with a simple HTML form?

-- What is the normal way to post XML from an HTML form to an ASP page?

--------------------------------------

thanks
-R
 
Yes, you will need an intermediary ASP page to ttake the posted data and put it into the XML format they are using at the warehouse before sending it to them. You could do this by using the HTML page and embedding a bunch of javascript to make an XML string to be posted to the warehouse, but then your dependant on the end user having javascript enabled and so on.
Basically What you want to do is accept the posted information from your HTML page. Then, as I said before, create an XML string that is in the format the data warehouse wants it posted in. Then you can just use the XMLHTTP object to send the XML string to the data warehouse's asp page.

If we pretend your data warehouse wants it in the format:
Code:
<invoice>
   <invoice_id>##</invoice_id>
   <order>
      <num>###</num>
      <amt>###</amt>
      <product_id>###</product_id>
   </order>
</invoice>
Then basically your new intermediary page would look something like this:
Code:
'1 --- Any validation you need to do

'2 --- Start building the XML string
Dim xml_string
xml_string = "<invoice>"

'pretend invoice_id passed as txtInvoiceId
xml_string = xml_string & "<invoice_id>" & Request.Form("invoice_id") & "</xml_string>"

'pretend amt and num and product_id were passed as txtAmt and txtNum and txtProductId
xml_string = "<invoice>"

xml_string = xml_string & _
   "<order>" & _
   "<num>" & Request.Form("txtNum") & "</num>" & _
   "<amt>" & Request.Form("txtAmt") & "</amt>" & _
   "<product_id>" & Request.Form("txtProductId") & "</product_id>" & _
   "</order>"

xml_string = xml_string & "</invoice>"

'3 --- Create the XMLHTTP object and send the xml data to our target address
Dim objXMLHTTP
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "POST","[URL unfurl="true"]http://www.targetServer.com/targetPage.asp",False[/URL]
objXMLHTTP.Send xml_string

'4 --- Get back the response from the remote server and display it to the user
If objXMLHTTP.Status <> 200 Then
   'server not found, dns not resolved, internal server error, etc
   Response.Write "An error occurred during the transaction, the error page follows: " & objXMLHTTP.ResponseText
Else
   'page was found, data submitted, these are the results generated by the remote server
   Response.Write objXMLHTTP.ResponseText
End If

What you should look at is what possible errors the remote page might send back, then I would add a case statement to the 200 section so that if there was an error in the XML formatting or a datavsalidation went bad you can display ther appropriate message rather than writing the raw response out to the browser. I would also do the same with the 400,401,500,etc status codes so that the user can get a nice message (Server currently unavailable or something like that) instead of seeing the error page.

Hope this helps,
-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
that's great help Tarwn, and now I have another problem, I can't run asp pages on Apache, do you know anything about this?
 
ASP only runs on Microsoft IIS and certsain 3rd-party applications for Apache. Your best bet would likely be a PHP page.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
yeah, I have been investigating that option too, but I am at a bit of a block with it too...

I know how to retrieve the data from a mysql database, but then I don't know how to post it with PHP, do you know anything about it?
 
I suggest posting this to one of the PHP, Tomcat or Apache boards on this website.

It seems to me that your PHP page needs to receive the posted form, convert that form to an XML document and in turn post that as an HTTP post to the remote server.

If this WERE an ASP developed solution and you were using Microsoft technologies, the server-side of the page posted to would grab the form variables, use MSXML to construct an XML document in memory, than use MSHTTP (I think that is the object name...not sure) to post the XML document to the remote server's webpage.

You will need to find equivalent technologies in Apache/PHP. I suspect Java and it's extensive libraries will provide all the equivalents you need.

But, the answer lies on the other boards.

TR
 
Sorry I couldn't help more, I can write PHP but I'm quite rusty, and I am definately not a master,

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top