<%@LANGUAGE="VBSCRIPT"%> <% '*******************************************************/ 'Process Broadbean XML files. '*******************************************************/ Function ProcessBroadBeanXML(xmlPost,method) '*******************************************************/ ' Setup Vars. '*******************************************************/ Dim basename, str, xdoc, fso, f '*******************************************************/ '*******************************************************/ '*******************************************************/ ' Load MSXML Object '*******************************************************/ Set xdoc = CreateObject("Msxml2.DOMDocument.3.0") xdoc.validateOnParse = True xdoc.async = False '*******************************************************/ '*******************************************************/ '*******************************************************/ ' Set type of import '*******************************************************/ ' Process File if (method = "file") then ' Get filename with FSO Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFile(xmlPost) basename = f.Name ' Clear fso Set fso = Nothing ' Load XML file with MSXML xdoc.load(xmlPost) ' Process Post ed xml ElseIf (method = "post") then basename = "Posted xml" xdoc.loadXML(xmlPost) ' If not write method pass crashout. Else response.Write("Unknown xmlPost '" & method & "' param sent to 'ProcessBroadBeanXML'
") End if '*******************************************************/ '*******************************************************/ '*******************************************************/ ' Check if xml format is correct '*******************************************************/ If xdoc.parseError.errorCode = 0 Then XMLerror = False '*******************************************************/ ' Set Values with Xpath ' Use xpath query to return node values. 'may be better way to retrieve values? '*******************************************************/ Set command_Value = xdoc.selectSingleNode("//job[0]/command[0]") Set contact_name_Value = xdoc.selectSingleNode("//job[0]/contact_name[0]") Set contact_email_Value = xdoc.selectSingleNode("//job[0]/contact_email[0]") Set contact_telephone_Value = xdoc.selectSingleNode("//job[0]/contact_telephone[0]") Set contact_url_Value = xdoc.selectSingleNode("//job[0]/contact_url[0]") Set days_to_advertise_Value = xdoc.selectSingleNode("//job[0]/days_to_advertise[0]") Set job_reference_Value = xdoc.selectSingleNode("//job[0]/job_reference[0]") Set job_title_Value = xdoc.selectSingleNode("//job[0]/job_title[0]") Set job_type_Value = xdoc.selectSingleNode("//job[0]/job_type[0]") Set job_duration_Value = xdoc.selectSingleNode("//job[0]/job_duration_Value[0]") Set job_startdate_Value = xdoc.selectSingleNode("//job[0]/job_startdate[0]") Set job_skills_Value = xdoc.selectSingleNode("//job[0]/job_skills[0]") Set job_description_Value = xdoc.selectSingleNode("//job[0]/job_description[0]") Set job_branchname_Value = xdoc.selectSingleNode("//job[0]/BranchName[0]") Set job_location_Value = xdoc.selectSingleNode("//job[0]/job_location[0]") Set job_industry_Value = xdoc.selectSingleNode("//job[0]/job_industry[0]") Set salary_Value = xdoc.selectSingleNode("//job[0]/salary[0]") '*******************************************************/ '*******************************************************/ '*******************************************************/ ' Create vparam array of xml values for Store Procedures '*******************************************************/ dim vParams(13), vParams2(0) 'vParams(0) = "" vParams(1) = job_reference_Value.text 'jobref vParams(2) = job_title_Value.text 'jobtitle vParams(3) = salary_Value.text 'salary vParams(4) = job_description_Value.text 'description vParams(5) = job_location_Value.text 'location vParams(6) = contact_name_Value.text 'contactName vParams(7) = contact_telephone_Value.text 'contactTelephone vParams(8) = contact_email_Value.text 'contactEmail vParams(9) = "" 'contactFax vParams(10) = job_branchname_Value.text 'Branch vParams(11) = job_industry_Value.text 'Sector vParams(12) = LookUpDetails("JobType",job_type_Value.text) 'jobType vParams(13) = "30" 'archive ' Set jobref array. vParams2(0) = vparams(1) '*******************************************************/ '*******************************************************/ '*******************************************************/ '####Post the params into your DB with Store Procedures.##### '####I`ll leave you to create your own SP to map the xml values into you DB#### '*******************************************************/ '*******************************************************/ 'XML Commands from BB '*******************************************************/ 'add job If (command_Value.text = "Add") then 'first, check that the job ref no doesn't already exist in ref col. set oRS = RunSP("spSBJobRefExists",vParams2) 'check if job reference exists.. If not oRS is nothing then str = str & "
Error:: This Job Reference Already Exists!" XMLerror = True Else 'Create Job set oRS = RunSP("spSBCreateJob",vParams) End if 'delete job ElseIf (command_Value.text = "Delete") then set oRS = RunSP("CA_archivejobs_byref",vParams2) 'XML command node != add or delete - return error msg Else str = str & "
Error:: Unknown Command Sent? - " & command_Value.text XMLerror = True End if '*******************************************************/ '*******************************************************/ '*******************************************************/ 'if error insert warning otherwise success message '*******************************************************/ if (XMLerror) then str = "

WARNING

" & str 'else pass success else str = "

SUCCESS

" & basename & " is valid!" end if '*******************************************************/ '*******************************************************/ '*******************************************************/ 'if xml format incorrect write out error + description '*******************************************************/ ElseIf xdoc.parseError.errorCode <> 0 Then ' Debug if file/post str = basename & " is not valid" & vbCrLf & _ xdoc.parseError.reason & "
URL: " & Chr(9) & _ xdoc.parseError.url & vbCrLf & "
Code: " & Chr(9) & _ xdoc.parseError.errorCode & vbCrLf & "
Line: " & _ Chr(9) & xdoc.parseError.line & vbCrLf & _ "
Char: " & Chr(9) & xdoc.parseError.linepos & vbCrLf & _ "
Text: " & Chr(9) & xdoc.parseError.srcText & _ "
XML POST: " & Chr(9) & xmlPost End If '*******************************************************/ '*******************************************************/ '*******************************************************/ 'Clear msxml '*******************************************************/ Set xdoc = Nothing '*******************************************************/ '*******************************************************/ '*******************************************************/ ' Store Info string. '*******************************************************/ ProcessBroadBeanXML = str '*******************************************************/ End Function '*******************************************************/ '*******************************************************/ '*******************************************************/ 'Setup XML process. '*******************************************************/ 'xmlPost = "D:\broadbean\test.xml" xmlPost = request("xmlPost") '*******************************************************/ '*******************************************************/ '*******************************************************/ 'Process xml and write output. '*******************************************************/ Response.Write(ProcessBroadBeanXML(xmlPost,"post")) '*******************************************************/ '*******************************************************/ %>