471,624 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

Change returned data content type?

Bit of a toughie here I think.

I use (access 2003) HTTP.send function to open up a php file that's stored on an internal website.
The file queries one of our suppliers regarding stock (with xml format) and returns the response.
The php selects the nodes I want to display to the users, and Access displays it as a message box.

What I'd like to do, is return the selected nodes in a way that Access could automatically pick up and insert into fields in the database.

I use the http.send function for another, which directly posts to the suppliers website and returns the full xml; which I can then use
Expand|Select|Wrap|Line Numbers
  1. Set price = HTTP.responseXML.SelectSingleNode("//query/price")
to get the selected node.

I tried echoing the nodes into an xml format and extracting those; but it kept saying 'variable not set'. I have a hunch that might be because the content type is text, not xml.

Does anyone know if it's possible to return the selected nodes as xml so I can pick them up in access?

Does anyone even understand what I'm going on about lol

Thanks for any help
Mandi
Oct 10 '08 #1
5 1203
pbmods
5,821 Expert 4TB
Heya, Mandi.

Which programming language are you using? That doesn't look like PHP.
Oct 10 '08 #2
Heya, Mandi.

Which programming language are you using? That doesn't look like PHP.
That part isn't, that part is VBA. I'll post both the VBA and PHP.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $td_sku = $_REQUEST['sku'];
  3. $td_manu = $_REQUEST['manu'];
  4.  
  5. //Following the XML data
  6. $xmldata="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r
  7. <OnlineCheck>\r
  8. <Header>\r
  9. <BuyerAccountId>xxxxx</BuyerAccountId>\r
  10. <AuthCode>xxxxx-xxxxx-xxxxx</AuthCode>\r
  11. <Type>Full</Type>\r
  12. </Header>\r
  13. <Item line=\"1\">\r
  14. <ManufacturerItemIdentifier>$td_manu</ManufacturerItemIdentifier>t\r
  15. <ResellerItemIdentifier/>\r
  16. <DistributorItemIdentifier>$td_sku</DistributorItemIdentifier>\r
  17. <Quantity>1</Quantity>\r
  18. </Item>\r
  19. </OnlineCheck>";
  20.  
  21. $fp = fsockopen("supplierswebsite.com", 8080, $errno, $errstr, 15);
  22. //Generate the postdata on a valid way, $out4 needs to be calculated, so will be later.
  23. $out1 = "POST /Onlchk HTTP/1.0\r
  24. ";
  25. $out2 = "Content-Type: multipart/form-data; boundary=---------------------------2\r
  26. ";
  27. $out3 = "Host: supplierswebsite.com:8080\r
  28. ";
  29. $out5 = "Connection: close\r
  30. \r
  31. ";
  32. $out6 = "-----------------------------2\r
  33. ";
  34. $out7 = "Content-Disposition: form-data; name=\"onlinecheck\"\r
  35. \r
  36. ";
  37. $out8 = "\r
  38. -----------------------------2--";
  39.  
  40. //Calculation of the Content-Length:
  41. $tlen=strlen($out6)+strlen($out7)+strlen($xmldata)+strlen($out8);
  42. $out4 = "Content-Length: $tlen\r
  43. ";
  44.  
  45. //Generate full output
  46. $out = $out1.$out2.$out3.$out4.$out5.$out6.$out7.$xmldata.$out8;
  47. fwrite($fp, $out);
  48. $retval = "";
  49. while(!feof($fp)){$retval = "$retval".fgets($fp,128);}
  50. fclose($fp);
  51. list($headers,$body) = explode("<?xml version=\"1.0\" encoding=\"UTF-8\"?>",$retval);
  52. $doc = new DOMDocument();
  53. $doc ->LoadXML($body);
  54. $item_ids = $doc->getElementsByTagname( "OnlineCheck" );
  55. foreach( $item_ids as $item )
  56.  
  57.  {
  58.  $error_s = $item->getElementsByTagName( "Errorstatus" ); $tderror = $error_s->item(0)->nodeValue;
  59.  $stock_s = $item->getElementsByTagName( "AvailabilityTotal" ); $tdstock = $stock_s->item(0)->nodeValue;
  60.  $desc_s = $item->getElementsByTagName( "ProductDesc" ); $tddesc = $desc_s->item(0)->nodeValue;
  61.  $est_s = $item->getElementsByTagName( "EstimatedDeliveryQuantity" ); $tdestqty = $est_s->item(0)->nodeValue;
  62.  $estd_s = $item->getElementsByTagName( "EstimatedDeliveryDate" ); $tdestdate = $estd_s->item(0)->nodeValue;
  63.  $sku_s = $item->getElementsByTagName( "DistributorItemIdentifier" ); $tdsku = $sku_s->item(0)->nodeValue;
  64.  $manu_s = $item->getElementsByTagName( "ManufacturerItemIdentifier" ); $manu = $manu_s->item(0)->nodeValue;
  65.  
  66.  // Reformatting the price to ISO compatible format
  67.  $price_s = $item->getElementsByTagName( "UnitPriceAmount" ); $tdprice = $price_s->item(0)->nodeValue;
  68.  }
  69. //Process details under here
  70. echo "Supplier Part No: $tdsku \r
  71. Manuf Part No: $manu \r
  72. Product: $tddesc \r
  73. Stock: $tdstock \r
  74. Price: $tdprice";
  75. ?>
The above is what the suppliers sent me and I'm aware it's probably not the best way of doing it, but it (now) works. From "//Process details under here" is what I wrote to check it works.

Expand|Select|Wrap|Line Numbers
  1. Sub test()
  2.  
  3. Dim myHTTP As MSXML2.xmlhttp
  4. Dim myDom As MSXML2.DOMDocument
  5. Dim qty, price, desc As MSXML2.IXMLDOMNode
  6. Dim myxml   As String
  7. sku = "1463230"
  8. manu = ""
  9.  
  10. Set myHTTP = CreateObject("msxml2.xmlhttp")
  11. Set myDom = CreateObject("MSXML2.DOMDocument")
  12.  
  13. myHTTP.Open "GET", "http://10x.0xx.0xx.xxx/c2000test.php?manu=" & manu & "&sku=" & sku, False
  14. myHTTP.send
  15.  
  16. MsgBox myHTTP.responseText, vbOKOnly, "Stock"
  17.  
  18. '   Set code = myHTTP.responseXML.selectSingleNode("//StockCheck/Price")
  19. '   MsgBox code
  20. Set myHTTP = Nothing
  21. End Sub
  22.  
The commented two lines near the bottom are what I'd like to be able to do, if at all possible.
Oct 10 '08 #3
I've found the following code that chucks out xml; but it still doesn't let me select the nodes.

Expand|Select|Wrap|Line Numbers
  1. $output= "<Order>\r
  2. <sku>$tdsku</sku>\r
  3. <desc>$tddesc</desc>\r
  4. <stock>$tdstock</stock>\r
  5. <price>$tdprice</price>\r
  6. </Order>";
  7. $xmlDoc = new DOMDocument();
  8. $xmlDoc->LoadXML($output);
  9.  
  10. print $xmlDoc->saveXML();
When I say it chucks out xml, I mean it shows the text on a browser, but the source shows the full xml, tags included.
Oct 10 '08 #4
Oh god.

I hate it when I'm so dense.

It was as simple as adding
Expand|Select|Wrap|Line Numbers
  1. header("Content-Type: text/xml");
to the top of the php.

thanks anyway guys =)
Oct 10 '08 #5
pbmods
5,821 Expert 4TB
Glad to hear you got it working! Thanks for posting your solution!
Oct 10 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.