Skip to main content

Search Records into XML Using PHP

There is an example for search items or block into xml using php with simplexml_load_string method or function, this will return you record block for particular query.

query = us

CODE:
1 :  <?php
2 :       # parm query=delhi , us
3 :       $xmlStr = '<?xml version="1.0" encoding="utf-8"?>
4 :                           <temprature>
5 :                           <item>
6 :                                <city>Bareilly</city>
7 :                                <state>Uttar Pradesh</state>
8 :                                <country>India</country>
9 :                                <lat>32.4567</lat>
10 :                                <lon>34.4567</lon>
11 :                                <temp>43.0</temp>
12 :                           </item>
13 :                           <item>
14 :                                <city>Haldwani</city>
15 :                                <state>Uttarakhand</state>
16 :                                <country>India</country>
17 :                                <lat>33.4567</lat>
18 :                                <lon>34.4567</lon>
19 :                                <temp>44.0</temp>
20 :                           </item>
21 :                           <item>
22 :                                <city>Delhi</city>
23 :                                <state>Delhi</state>
24 :                                <country>India</country>
25 :                                <lat>35.4567</lat>
26 :                                <lon>36.4567</lon>
27 :                                <temp>45.0</temp>
28 :                           </item>
29 :                           <item>
30 :                                <city>Jaipur</city>
31 :                                <state>Rajasthan</state>
32 :                                <country>India</country>
33 :                                <lat>36.4567</lat>
34 :                                <lon>37.4567</lon>
35 :                                <temp>48.0</temp>
36 :                           </item>
37 :                           </temprature>';
38 :       $xmlo = simplexml_load_string($xmlStr);
39 :       $i=0;
40 :       foreach($xmlo->item as $c){
41 :            foreach($c->children() as $ch){
42 :                 if(strtolower($ch) == strtolower($_GET["query"])){
43 :                      @header("content-type: text/xml");
44 :                      echo $xmlo->item[$i]->asXML();
45 :                      exit;
46 :                 }
47 :            }
48 :            $i++;
49 :       }
50 :       @header("content-type: text/xml");
51 :       echo "<Error>No item found!</Error>";
52 :       exit;
53 :  ?>

Comments

Popular posts from this blog

Flex Interview Questions

1) What is Flex? Flex is used to devleop Rich Internet Application (RIA) You can both desktop & web based applicaiton.It is markup language and object-oriented languages its many syntax match with flash action script. Flex Developers use typically five distinct phases to develoep Rich Internet Application. Design Configure Build Deploy Secure 2) How do i get Page URL and Query String ? We can use mx.core.Application.application.url (mx.core)package to work with current page URL. & query string. 3) Describe flex component file types ? There are following file types we can use in flex. extension .mxml - a component implemented as an MXML file. extension .as - a component implemented as an ActionScript class. extension .swc - a SWC file contains components in a packge. 4) Difference between target & currentTarget ? target : This property is set by the dispatchEvent() method. You cannot change this to a different object. currentTarget : This property is set by component instan...

PHP Interview Questions

What are the difference between require_once and include, include_once? require_once(), include_once() both the functions include script once in file even it include many times using *_once function. require() and include() function provide facility to include file many times in script file. What is the difference between mysql_fetch_object & mysql_fetch_array? There is only difference between mysql_fetch_object() and mysql_fetch_array(). mysql_fetch_object() : it is return an object. mysql_fetch_array() : it is return an Array. In mysql_fetch_object() you can access the data by the field names whereas in mysql_fetch_array() you can access data by it's offsets. Who is the father of PHP ? Rasmus Lerdorf is know as a father of PHP. What is PHP ? PHP Hypertext Preprocessor is An open source server side scripting language/programming language used to create dynamic web pages that allows web developers to create dynamic pages that interacts with databases.

How To Change Form Action at Runtime

How to change Form action at runtime using javascript. This the example which will change html form action at runtime. CODE: 1 :   <html> 2 :   <head> 3 :   <Script Language="javascript"> 4 :   function change_action(){ 5 :   var frm_obj=document.getElementById("frm"); 6 :   frm_obj.action="http://www.google.com"; 7 :   } 8 :   </Script> 9 :   </head> 10 :   <body> 11 :   <form id="frm" action="abc.php" method="post" onsubmit="return change_action()"> 12 :   UID &nbsp;&nbsp;<input type="text"><br> 13 :   PWD <input type="Password"><br><br> 14 :   <input type="submit" value="submit"> 15 :   </form> 16 :   </body> 17 :   </html>