473,466 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to hyperlink CDATA in PHP

8 New Member
i have comparison website and a deep link in xml is given when parameters are input. However i have CDATA which is always changing depending on what booking parameters are. This CDATA is a URL followed by code. I need to be able to select the CDATA when a 'submit' button is clicked. any ideas. below is PHP code that provides parameters such as location, time, etc but stuck on CDATA. The CDATA is within <book> section of XML.

Expand|Select|Wrap|Line Numbers
  1.  Thanks for this but cannot seem to make this work. When i do i just get the URL string listed on the webpage?. Here is the list_car1.php file.
  2.  
  3.  
  4.  
  5. var timeout;
  6. function checkLoccode(sobj) {
  7. if (sobj.options[sobj.selectedIndex].value=='--other countries--') {
  8. //getUrl('GET', 'http://' + location.host + '/cgi-bin/gen5?runprog=thajaxlog&log=prepaid_from_home', true, ajaxLogCallBack);
  9. timeout=setTimeout("callRedirect()",3000);
  10. }
  11. }
  12. function ajaxLogCallBack() {
  13. if (requestObject.readyState == 4) {
  14. if (requestObject.status==200) {
  15. clearTimeout(timeout);
  16. callRedirect();
  17. }
  18. }
  19. }
  20. function callRedirect() {
  21. location.href='http://worldwide.thrifty.com';
  22. }
  23.  
  24. function GetXmlHttpObject()
  25. {
  26. var xmlHttp1=null;
  27. try
  28. {
  29. // Firefox, Opera 8.0+, Safari
  30. xmlHttp1=new XMLHttpRequest();
  31. }
  32. catch (e)
  33. {
  34. // Internet Explorer
  35. try
  36. {
  37. xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP");
  38. }
  39. catch (e)
  40. {
  41. xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP");
  42. }
  43. }
  44. return xmlHttp1;
  45. }
  46.  
  47. function submit_form()
  48. {
  49. var url;
  50. url="http://www.thrifty.co.uk/cgi-bin/gen5?runprog=thxml&xsrc=7qhfqou3&mode=quote";
  51. url+="&xloc="+document.xmlcnt.loccode.value;
  52. url+="&xlocdrop="+document.xmlcnt.locdrop.value;
  53. url+="&xonewaystart="+document.xmlcnt.onewaystart.value;
  54. url+="&xonewayend="+document.xmlcnt.onewayend.value;
  55. url+="&xbook="+document.xmlcnt.book.value;
  56. url+="&xpuyear="+(document.xmlcnt.pu_month.value).substr(0,4);
  57. url+="&xpumonth="+(document.xmlcnt.pu_month.value).substr(4);
  58. url+="&xpuday="+document.xmlcnt.pu_day.value;
  59. url+="&xputime="+document.xmlcnt.pu_time.value;
  60. url+="&xdbyear="+(document.xmlcnt.db_month.value).substr(0,4);
  61. url+="&xdbmonth="+(document.xmlcnt.db_month.value).substr(4);
  62. url+="&xdbday="+document.xmlcnt.db_day.value;
  63. url+="&xdbtime="+document.xmlcnt.db_time.value;
  64. url+="&xclass="+document.xmlcnt.vehicle_type.value;
  65. url+="&randval="+Math.random();
  66.  
  67. //url="http://www.google.com"
  68.  
  69. xmlHttp1=GetXmlHttpObject();
  70. if (xmlHttp1==null)
  71. {
  72. alert ("Your browser does not support AJAX!");
  73. return;
  74.  
  75. xmlHttp1.onreadystatechange=function()
  76. {
  77. if(xmlHttp1.readyState==4)
  78. {
  79. document.xmlcnt.xmlsrc.value=xmlHttp1.responseText;
  80. document.xmlcnt.submit();
  81. }
  82. }
  83.  
  84. xmlHttp1.open("GET",url,true);
  85. xmlHttp1.send(null);
  86. }
  87. </script>
  88.  
  89.  
  90.  
  91. <?php
  92. //ini_set("disable_functions",null);
  93. //phpinfo();
  94.  
  95. $string="http://www.thrifty.co.uk/cgi-bin/gen5?runprog=thxml&xsrc=7qhfqou3&mode=quote";
  96. $string.="&xloc=".$_REQUEST["loccode"];
  97. $string.="&xlocdrop=".$_REQUEST["locdrop"];
  98. $string.="&xbook=".$_REQUEST["book"];
  99. $string.="&xonewaystart=".$_REQUEST["onewaystart"];
  100. $string.="&xonewayend=".$_REQUEST["onewayend"];
  101. $string.="&xpuyear=".substr($_REQUEST["pu_month"],0,4);
  102. $string.="&xpumonth=".substr($_REQUEST["pu_month"],4);
  103. $string.="&xpuday=".$_REQUEST["pu_day"];
  104. $string.="&xputime=".$_REQUEST["pu_time"];
  105. $string.="&xdbyear=".substr($_REQUEST["db_month"],0,4);
  106. $string.="&xdbmonth=".substr($_REQUEST["db_month"],4);
  107. $string.="&xdbday=".$_REQUEST["db_day"];
  108. $string.="&xdbtime=".$_REQUEST["db_time"];
  109. $string.="&xclass=".$_REQUEST["vehicle_type"];
  110.  
  111.  
  112.  
  113.  
  114.  
  115. /*
  116. function get_data($url)
  117. {
  118. $ch = curl_init();
  119. $timeout = 5;
  120. curl_setopt($ch,CURLOPT_URL,$url);
  121. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  122. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  123. $data = curl_exec($ch);
  124. curl_close($ch);
  125. return $data;
  126. }
  127. echo get_data($string);
  128.  
  129.  
  130. function proxy_url($proxy_url)
  131. {
  132. $proxy_name = '127.0.0.1';
  133. $proxy_port = 4001;
  134. $proxy_cont = '';
  135.  
  136. $proxy_fp = fsockopen($proxy_name, $proxy_port);
  137. if (!$proxy_fp) {return false;}
  138. fputs($proxy_fp, "GET $proxy_url HTTP/1.0\r\nHost: $proxy_name\r\n\r\n");
  139. while(!feof($proxy_fp)) {$proxy_cont .= fread($proxy_fp,4096);}
  140. fclose($proxy_fp);
  141. $proxy_cont = substr($proxy_cont, strpos($proxy_cont,"\r\n\r\n")+4);
  142. return $proxy_cont;
  143.  
  144. echo proxy_url($string);*/
  145.  
  146.  
  147. function XML2Array ( $xml , $recursive = false )
  148. {
  149. if ( ! $recursive )
  150. {
  151. $array = simplexml_load_string ( $xml ) ;
  152. }
  153. else
  154. {
  155. $array = $xml ;
  156. }
  157.  
  158. $newArray = array () ;
  159. $array = ( array ) $array ;
  160. foreach ( $array as $key => $value )
  161. {
  162. $value = ( array ) $value ;
  163. if ( isset ( $value [ 0 ] ) )
  164. {
  165. $newArray [ $key ] = trim ( $value [ 0 ] ) ;
  166. }
  167. else
  168. {
  169. $newArray [ $key ] = XML2Array ( $value , true ) ;
  170. }
  171. }
  172. return $newArray ;
  173. }
  174.  
  175. function disp_date($str)
  176. {
  177. $y=substr($str,0,4);
  178. $m=substr($str,4,2);
  179. $d=substr($str,6,2);
  180. //echo $y."-".$m."-".$d;
  181. return date("M d, Y",strtotime($y."-".$m."-".$d));
  182. }
  183.  
  184. $handle = fopen($string, "r");
  185. $xml_string="";
  186. // If there is something, read and return
  187. if ($handle) {
  188. while (!feof($handle)) {
  189. $buffer = fgets($handle, 4096);
  190. $xml_string.=$buffer;
  191. }
  192. fclose($handle);
  193. }
  194.  
  195. //$xmlDoc = new DOMDocument();
  196. $xmlDoc=simplexml_load_string ( $xml_string ) ;
  197.  
  198. ?> 
  199.  
  200.  
  201. <?
  202.  
  203. //print_r($xmlDoc);
  204.  
  205. echo "<br><strong/>Pick up Location: ".$xmlDoc->hire->locname."<br> Drop-off Location: ".$xmlDoc->hire->locdrop."<br>Pickup Time: ".disp_date($xmlDoc->hire->pickupdate)." ".$xmlDoc->hire->pickuptime."<br>Dropback Time: ".disp_date($xmlDoc->hire->dropbackdate)." ".$xmlDoc->hire->dropbacktime."<br>";
  206.  
  207. echo "<table border=1 style='font:12px verdana' cellspacing=0 cellpadding=3><tr><td>Car Type</td><td>Description</td><td>Rate</td></tr>";
  208. foreach($xmlDoc->car as $car)
  209. {
  210. echo "<tr><td width=200px><img src='".$car->carimage."' align='right' style='padding:1px; width:100px'><b>".$car->cartype."</b><br>".$car->carsipp."<br>".$car->transmission."</td><td><b>".$car->carexample."</b></td><td><b>&pound;".$car->price."
  211. </b><br>Unlimited Miles</b><br><input type='submit' name='Book' value='Book'><br>".$url = (string)$car->book."</br></b></td></tr>";
  212.  
  213.  
  214. echo "</form>";
  215. echo "<form method='post' action='book1.php'>";
  216.  
  217. }
  218. echo "</table>";
  219. ?>
  220.  
  221. </span>
  222. </p>
  223. </p>
  224. <p>&nbsp; </p>
  225. <p> <span class="row1"><div class="separate"></div>
  226. </span></p>
  227.  
  228.  
  229.  
  230.  
Sep 20 '11 #1

✓ answered by Dormilich

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $ex = <<<DOC
  3. <?xml version="1.0" ?>
  4. <root>
  5.     <item>1</item>
  6.     <item><![CDATA[<2>]]></item>
  7. </root>
  8. DOC;
  9. $xml = new DOMDocument;
  10. $xml->loadXML($ex);
  11. echo $xml->getElementsByTagName("item")->item(1)->firstChild->data;

7 2769
Dormilich
8,658 Recognized Expert Moderator Expert
I don’t see any CDATA* in your code … besides, XMLHttpRequest.responseText only has the data type string.


* - <![CDATA[this is the CDATA content]]>
Sep 20 '11 #2
alltech
8 New Member
The CDATA is generated from the following for example see following code which is generated when vehicle picked up from heathrow..this link gives XML and within this CDATA is there for each car


http://www.thrifty.co.uk/cgi-bin/gen...10:00&xclass=M




@alltech
Sep 20 '11 #3
Dormilich
8,658 Recognized Expert Moderator Expert
you access it like a standard text node, e.g. //book
Sep 21 '11 #4
alltech
8 New Member
@Dormilich
can you give me example if possible????
Sep 21 '11 #5
Dormilich
8,658 Recognized Expert Moderator Expert
in PHP or in JavaScript?
Sep 21 '11 #6
alltech
8 New Member
give example in PHP please
Sep 21 '11 #7
Dormilich
8,658 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $ex = <<<DOC
  3. <?xml version="1.0" ?>
  4. <root>
  5.     <item>1</item>
  6.     <item><![CDATA[<2>]]></item>
  7. </root>
  8. DOC;
  9. $xml = new DOMDocument;
  10. $xml->loadXML($ex);
  11. echo $xml->getElementsByTagName("item")->item(1)->firstChild->data;
Sep 29 '11 #8

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

Similar topics

3
by: Balaras | last post by:
Hi, Can sombody here please help me a bit with a regular expression. I have a xml file where I need to strip the CDATA sections of any contained data. Eg. <xml> <tag><]></tag>...
6
by: Cade Perkins | last post by:
How can the CDATA ending delimiter "]]>" be represented within a CDATA section itself? Consider an XML document that is intended to contain an embedded, uninterpreted XML example. Generally,...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
1
by: soccerdad | last post by:
I've got a class hierarchy generated from a .xsd schema file using the XSD.EXE tool. One of the elements will have its "inner text" set to a CDATA block. The XSD.EXE tool exposed a "Value" property...
12
by: Peter Michaux | last post by:
Hi, I am experimenting with some of the Ruby on Rails JavaScript generators and see something I haven't before. Maybe it is worthwhile? In the page below the script is enclosed in //<!]> ...
7
by: Max | last post by:
Hello everyone! Can anyone help me to convert the CDATA expression "CDATA ::= (Char* - (Char* ']]>' Char*)" to Javascript Regular Expression? Thanks, Max
2
n8kindt
by: n8kindt | last post by:
i'm having problems with 1) putting a url into xml using php and once it is in a url 2) parsing it as a hyperlink... i've tried using &amp; and = to parse the url but i keep getting the 'XML...
6
by: dkyadav80 | last post by:
Hi sir, I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all...
3
by: vm35 | last post by:
I'm trying to access CDATA inside XML file, works fine in FF but not IE (pretty much all versions). If anyone has any suggestions, please help. Thanks in advance. XML:<?xml version="1.0"...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.