Jump to content

holsy

Members
  • Content Count

    27
  • Joined

  • Last visited

Community Reputation

1 Neutral

About holsy

  • Rank
    Newbie
  1. holsy

    Parse XML files?

    Sorry, posted twice by accident.
  2. holsy

    Parse XML files?

    Can anyone give me some pointers on how to parse xml files using asp? I have tried numerous examples searching google but can't get it to work. I have not performed an xml read before. Here is the xml file structure (note: this xml file has no root element). <?xml version="1.0" encoding="utf-8"?><item><supplier_id>2006</supplier_id><drop_ship_fee>3.00</drop_ship_fee><supplier_name>Beethoven</supplier_name><product_id>4185456</product_id><product_sku>340</product_sku><item_last_update>2011-12-31 15:07:39.0</item_last_update><item_discontinued_date></item_discontinued_date><categories><category><category_id>7912</category_id><category_name>Catalog</category_name></category><category><category_id>10184</category_id><category_name>Kids, baby & toy</category_name></category><category><category_id>10196</category_id><category_name>Toy</category_name></category><category><category_id>10212</category_id><category_name>Puzzles</category_name></category></categories><attributes></attributes><folder_paths><folder_path><value><folder_id>1151651</folder_id><folder_name>Feb03_2012</folder_name></value><value><folder_id>1151664</folder_id><folder_name>Data Export - 2012-02-03 53</folder_name></value></folder_path></folder_paths><is_customized>0</is_customized></item><item><supplier_id>2006</supplier_id><drop_ship_fee>5.00</drop_ship_fee><supplier_name>Beethoven</supplier_name><product_id>4185486</product_id><product_sku>343</product_sku><item_last_update>2011-12-31 16:07:39.0</item_last_update><item_discontinued_date></item_discontinued_date><categories><category><category_id>4912</category_id><category_name>Catalog</category_name></category><category><category_id>10184</category_id><category_name>Kids, baby & toy</category_name></category><category><category_id>10196</category_id><category_name>Toy</category_name></category><category><category_id>10212</category_id><category_name>Puzzles</category_name></category></categories><attributes></attributes><folder_paths><folder_path><value><folder_id>1151651</folder_id><folder_name>Feb03_2012</folder_name></value><value><folder_id>1151664</folder_id><folder_name>Data Export - 2012-02-03 53</folder_name></value></folder_path></folder_paths><is_customized>0</is_customized></item> Here is the asp code. I have tried these example but can't get it to work: <%'Set the XML ObjectSet objXML = Server.CreateObject("Microsoft.XMLDOM")'Set Asynchoronous = falseobjXML.async = False'Load the XML file.'User Server.MapPath method is the XML is located in your site.'Else you can use the absolute path.objXML.Load (DestinationPath & "\" & strDatasource)'If there is any errors pasring the file the notifyIf objXML.parseError.errorCode <> 0 ThenResponse.Write "Error Parsing XML"Response.Write "Rason :" & objXML.parseError.reason & "Error Line: " & objXML.parseError.lineEnd If'Get ALL the Elements by the tag name bookSet myOBJ = objXML.getElementsByTagName("item")'Now Iterate through the List and DisplayFor i = 0 to (myOBJ.Length-1) Response.Write "supplier_id: " & books.item(i).childNodes(0).text & "<br/>" Response.Write "drop_ship_fee: " & books.item(i).childNodes(1).text & "<br/>" Response.Write "supplier_name: " & books.item(i).childNodes(2).text & "<br/>"Next%> The other example is: Dim objxmlSet objxml = Server.CreateObject("Microsoft.XMLDOM")objxml.async = Falseobjxml.load (DestinationPath & "\" & strDatasource) set ElemProperty = objxml.getElementsByTagName("item")set ElemSupplier_id = objxml.getElementsByTagName("item/supplier_id")set ElemDrop_ship_fee = objxml.getElementsByTagName("item/drop_ship_fee")set ElemSupplier_name = objxml.getElementsByTagName("item/supplier_name") For i=0 To (ElemProperty.length -1) Response.Write " Supplier ID = " Response.Write(ElemSupplier_id.item(i).Text) & "<br>" Response.Write " Drop Ship Fee = " Response.Write(ElemDrop_ship_fee.item(i).Text) & "<br>" Response.Write " Supplier Name = " Response.Write(ElemSupplier_name.item(i).Text) & "<br>"nextSet objxml = Nothing What am I doing wrong?
  3. Just tried it...and it works! javascript is not my forte. Thanks JamesB
  4. Hi There, Does anyone know what I am doing wrong in trying to pass a variable to use as a parameter. //Form Validationfunction validate(form) {var e = form.elements, m = '';if(!e['txtUserName'].value) {m += 'Username is required<br/>';}var xhReq = new XMLHttpRequest();var username = e['txtUserName'].value//alert(username);xhReq.open("GET", "checkusername.asp?username=\'' + username + '\'",false);xhReq.send(null);var serverResponse = xhReq.responseText;alert(serverResponse);if(!e['txtPassword1'].value) {m += 'Password is required<br/>';}if(!e['txtPassword2'].value) {m += 'Repeat Password is required<br/>';}if(e['txtPassword1'].value != e['txtPassword2'].value) {m += 'Your passwords does not match<br/>';}if(!/.+@[^.]+(\.[^.]+)+/.test(e['txtEmail'].value)) {m += 'Valid e-mail address is required<br/>';}var btn = valButton(form.radiobuttons);if (btn == null) {m += 'Please choose a plan<br/>';}if(!e['terms-conditions'].checked ) {m += 'Must agree to terms and conditions<br/>';}if(m) {//alert('The following error(s) occurred:\n\n' + m);message_box.show_message('Please Complete the Following:\n\n', m);return false;}return true;}function valButton(btn) { var cnt = -1; for (var i=btn.length-1; i > -1; i--) { if (btn[i].checked) {cnt = i; i = -1;} } if (cnt > -1) return btn[cnt].value; else return null;} I am able to read the variable: var username = e['txtUserName'].value by testing it with an alert box but am unable write the correct syntax to pass it to: xhReq.open("GET", "checkusername.asp?username=\'' + username + '\'",false);Can anyone help?Thank You
  5. thanks justsomeguy for pointing me in the right direction. I have finally got the synchronous ajax request to work! cheers!
  6. justsomeguy, Took your advice about sending an ajax request. From what I've read, it is the best way to go about this. I am trying something like this: //Form Validationfunction validate(form) {var e = form.elements, m = '';if(!e['txtUserName'].value) {m += 'Username is required<br/>';}var xhReq = new XMLHttpRequest();var strusername = e['txtUserName'].valuexhReq.open("GET", "checkusername.asp?username=\'' + strusername + '\'",false);xhReq.send(null);var serverResponse = xhReq.responseText;alert(serverResponse);if(!e['txtPassword1'].value) {m += 'Password is required<br/>';}if(!e['txtPassword2'].value) {m += 'Repeat Password is required<br/>';}if(e['txtPassword1'].value != e['txtPassword2'].value) {m += 'Your passwords does not match<br/>';}if([email="!/.+@[^.]+(.[^.]+)+/.test(e["]!/.+@[^.]+(\.[^.]+)+/.test(e['txtEmail'].value[/email])) {m += 'Valid e-mail address is required<br/>';}var btn = valButton(form.radiobuttons);if (btn == null) {m += 'Please choose a plan<br/>';}if(!e['terms-conditions'].checked ) {m += 'Must agree to terms and conditions<br/>';}if(m) {//alert('The following error(s) occurred:\n\n' + m);message_box.show_message('Please Complete the Following:\n\n', m);return false;}return true;}function valButton(btn) {var cnt = -1;for (var i=btn.length-1; i > -1; i--) {if (btn[i].checked) {cnt = i; i = -1;}}if (cnt > -1) return btn[cnt].value;else return null;} I am using an alert box to test the response which seems to be working with a value passed to checkusername.asp like this:xhReq.open("GET", "checkusername.asp?username=True",false);I am unable to pass a variable because I think I have the incorrect javascript syntax:var username = e['txtUserName'].value //can't retrieve text box value here xhReq.open("GET", "checkusername.asp?username=\'' + strusername + '\'",false);I have a test asp receiving page: <%Dim objRS, strUserName strUserName = Request.QueryString("username") Set objRS=Server.CreateObject("ADODB.Recordset") Set objRS.ActiveConnection=objConn objRS.CursorType=adOpenDynamic objRS.LockType=adLockOptimistic objRS.Open "SELECT * FROM users WHERE ([username] ='" & strUserName & "')",objConn IF objRS.EOF Then Else Response.Write "Exists" End If objRS.Close Set objRS = Nothing%> The perhaps I can catch the serverResponse ...if serverResponse == "exists" , then display the message box.
  7. I am pretty weak with my Ajax or javascript coding coming from a vbscript background however I did come up with an ugly solution that will allow me to continue with asp and should work for now cause I am staring at a deadline. 'Form Validation Response.Write "<script type=""text/javascript"">" & _ "function validate(form) {var e = form.elements, m = '';" & _ "if(!e['txtUserName'].value) {m += 'Username is required<br/>';}" 'ASP CODE HERE Dim objRS, strtemp, strUserName, strPassword, strEmail, strPlan, strResponse strUserName = trim(Request.form("txtUserName")) Set objRS=Server.CreateObject("ADODB.Recordset") Set objRS.ActiveConnection=objConn objRS.CursorType=adOpenDynamic objRS.LockType=adLockOptimistic objRS.Open "SELECT * FROM users WHERE ([username] ='" & strUserName & "')",objConn IF objRS.EOF Then Else response.Write "if(!e['txtTesting'].value) {m += 'Duplicate Name Detected<br/>';}" End If 'End ASP CODE Response.Write "if(!e['txtPassword1'].value) {m += 'Password is required<br/>';}" & _ "if(!e['txtPassword2'].value) {m += 'Repeat Password is required<br/>';}" & _ "if(e['txtPassword1'].value != e['txtPassword2'].value) {m += 'Your passwords does not match<br/>';}" & _ "if(!/.+@[^.]+(\.[^.]+)+/.test(e['txtEmail'].value)) {m += 'Valid e-mail address is required<br/>';}" & _ "var btn = valButton(form.radiobuttons);" & _ "if (btn == null) {m += 'Please choose a plan<br/>';}" & _ "if(!e['terms-conditions'].checked ) {m += 'Must agree to terms and conditions<br/>';}" & _ "if(m) {" & _ "message_box.show_message('Please Complete the Following:\n\n', m);" & _ "return false;" & _ "}" & _ "return true;" & _ "}" & _ "function valButton(btn) {" & _ "var cnt = -1;" & _ "for (var i=btn.length-1; i > -1; i--) {" & _ "if (btn[i].checked) {cnt = i; i = -1;}" & _ "}" & _ "if (cnt > -1) return btn[cnt].value;" & _ "else return null;" & _ "}" & _ "</script>" Now I am calling javascript within asp. I know it's not the best practice but it seems to be working..Except I am unable to retrieve a value from strUserName = trim(Request.form("txtUserName")) so I can use the variable in my SQL statement. I am using response.Write "if(!e['txtTesting'].value) {m += 'Duplicate Name Detected<br/>';}" just to force a message dialog when a duplicate record has been found.Any idea how I can retrieve a value for Request.form("txtUserName")
  8. Hi All, I am unable to do a check for duplicate records before the form is submitted to Paypal. Here is the form: <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post" onSubmit="return validate(this);"><input name="txtUserName" id="txtUserName" type="Text" tabindex="1" /><input name="txtPassword1" type="password" tabindex="2" /><input name="txtPassword2" type="password" tabindex="3" /><input name="txtEmail" type="Text" tabindex="4" /></form> I am doing javascript client side validation with this block of code: //Form Validationfunction validate(form) {var e = form.elements, m = '';if(!e['txtUserName'].value) {m += 'Username is required<br/>';}if(!e['txtPassword1'].value) {m += 'Password is required<br/>';}if(!e['txtPassword2'].value) {m += 'Repeat Password is required<br/>';}if(e['txtPassword1'].value != e['txtPassword2'].value) {m += 'Your passwords does not match<br/>';}if(!/.+@[^.]+(\.[^.]+)+/.test(e['txtEmail'].value)) {m += 'Valid e-mail address is required<br/>';}var btn = valButton(form.radiobuttons);if (btn == null) {m += 'Please choose a plan<br/>';}if(!e['terms-conditions'].checked ) {m += 'Must agree to terms and conditions<br/>';}//if (recaptcha_confirm == null) {m += 'reCaptcha Probs<br/>';}//if (reCaptchaResponse.isValid()) {out.print("Answer was entered correctly!");} else {m += 'reCaptcha Wrong<br/>';}if(m) {//alert('The following error(s) occurred:\n\n' + m);message_box.show_message('Please Complete the Following:\n\n', m);return false;}return true;}function valButton(btn) { var cnt = -1; for (var i=btn.length-1; i > -1; i--) { if (btn[i].checked) {cnt = i; i = -1;} } if (cnt > -1) return btn[cnt].value; else return null;} The javascript form validation works. The problem is now I want to check for duplicate usernames using asp, then continue with the form submit to Paypal if ther are no duplicates. I am unable to catch the submit action with: IF request.Form.Count > 0 THENORIf Request.ServerVariables("HTTP_METHOD") = "POST" Then I realize that the onSubmit="return validate(this);" on the form calls the validation but how can I check for duplicate records using asp before the form is sent to paypal?Any ideas?
  9. Finally solved it with suggestion from justsomeguy: selCrit = "OR" strInput = Request.form("searchbox") arrSearch = split(strInput, " ") strSQL = "SELECT * FROM videos WHERE" strCombine = join(arrSearch, "%') " & selCrit & " (tags LIKE '%") strSQL = strSQL & " (tags LIKE '%" & strCombine & "%')" Thanks for the suggestion. My headache is gone now
  10. How about something like this OR statement? Dim ListArray sqlCriteria = trim(Request.QueryString("searchbox")) ListArray = split(sqlCriteria, " ") For loopctr = 0 to Ubound(ListArray) NewItem = "tags='" & ListArray(loopctr) & "'" response.Write NewItem response.write "<br>" If Len(SqlCriteria) > 0 Then JoinStatement = " OR " Else JoinStatement = "" End if MySqlCriteria = MySqlCriteria & JoinStatement & NewItem Next sSQL = "Select * From videos Where " & MySqlCriteria response.Write sSQL I found this online but it is currently spitting out garbage:Response.Write sSQL displays: Select * From videos Where OR tags='socks' OR tags='white' OR tags='cotton'The OR is inserted right after the WHERE clause. I tried to hard code the SQL statement just to test and got no returns. I don't get it, before trying using the SQL IN statements, I read from here: http://www.techonthenet.com/sql/in.php that it does work. Hmmm..confused now
  11. Hi All, I have a multiple word function that I am having trouble getting the SQL IN statement to return any records. I want to return records containing ANY of the search query words. Here is the code: Dim thisArray, i, sqlCriteria sqlCriteria = trim(Request.QueryString("searchbox")) thisArray = split(sqlCriteria, " ") sSQL = "SELECT * FROM videos WHERE tags IN ('" & Join(thisArray, "','") & "')" The sqlCriteria = trim(Request.QueryString("searchbox")) is receiving the url parameter string of: ?searchbox=socks+white+cottonThe words are seperated with a "+" sign. Somehow, the split(sqlCriteria, "+") doesn't parse the words correctly, but when I use split(sqlCriteria, " "); it works.I did a response.write sSQL that reads : SELECT * FROM videos WHERE tags IN ('socks','white','cotton')The "tags" field in the ms access database is a memo field with words seperated with a space. Here is how I open the recordset: dim objConn, sConnectset objConn=Server.CreateObject("ADODB.connection")sConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/db_folder/mydb.mdb")objConn.ConnectionString=sConnectobjConn.openRecordset.CursorLocation = 3Recordset.open sSQL, objConn not sure why it's not working, am I missing something?
  12. Installed tamper addon for Firefox and viewed the outgoing data. The "content" did show an encoded string outgoing and I tried using the Form("content").Value and Form("content") to read the form item. Still nothing however the javascript alert box did show the value: onSubmit:function submitData(content){alert(content.current)}, Just can't my asp script to read the content. Hmmm..still stumped but really appreciate the help and responses justsomeguy. May just leave it for now and may get an a-ha moment.
  13. The current form includes an upload component and is type ENCTYPE="multipart/form-data". All processing is done on the same page as well; the code detects a form post and processes uploads, text box entries, etc. Everything is working fine. I am able to get ipweditor to work client side but have no idea how to read the values from Ipweditor. Using ASP Pure Upload, I am using Form("textboxvalue").Value instead of Request.Form. With ipweditor, I have tried Form("content").value, Form("content.current").value, and other ways of trying to get the value without any luck. Javascript is not my strongest forte.
  14. I'm using an upload component for file uploads.
  15. So, I can remove: $.ajax({ type: "POST",url: "save.php", data: {"content": content.current}, complete: function(){ }, //manage the complate if needed success: function(html){ }//get some data back to the screen if needed However, I am still unable to make the correct call to retrieve the values on the retrieving page. The php example is of little use to me. I am currently retrieving values via ENCTYPE="multipart/form-data" with Pure Asp Upload (ex."Form("form-component").Value"); I have tried Form("content").Value using asp but cannot retrieve a value. Any ideas how to retrieve it in javascript?
×
×
  • Create New...