www.webdeveloper.com
Results 1 to 4 of 4

Thread: Blank response in XML WebService

Threaded View

  1. #1
    Join Date
    Sep 2006
    Posts
    655

    Question Blank response in XML WebService

    Hi

    I am trying to create a webservice that would output either in JSON or XML format depending on the user's choice.

    I problem comes when I am sending a boolean datatype to the user in XML format.

    When the datatype is true, it sends the following:
    Code:
    <?xml version='1.0' encoding='UTF-8'?> 
    <output> 
     <result>1</result> 
    </output>

    But when the datatype is false, it sends blank value under <result>:
    Code:
    <?xml version='1.0' encoding='UTF-8'?> 
    <output> 
     <result></result> 
    </output>

    But it works well when the format is JSON:

    In case of true:
    Code:
    {"result":true}
    In case of false:
    Code:
    {"result":false}


    Here is my code that generates XML or JSON:

    Code:
    			
    			$mode = 'XML'; //Change to XML or JSON
    			
                $return = array(
                    'result' => true
                );		
                	
                if('XML' == $mode){
    		        //XML	
    		        print "<?xml version='1.0' encoding='UTF-8'?>\n";
    		        print "<output>\n";
    		        foreach ($return as $element => $content) {
    		           print "<$element>";
    		           print $content;
    		           print "</$element>\n";
    		        }
    		        print "</output>";
    		        exit();  
    		                  
                }else{
    				//JSON
    				echo(json_encode($return) );die;            
                }


    Can someone please help me understand this mystery?


    Thanks
    Last edited by phantom007; 05-05-2013 at 11:46 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles