php - posting data to another url in XML format -
this first controller xmlpost.php
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class xmlpost extends ci_controller { public function index() { $this->load->view('my_view'); $data["id"] = $this->input->post("id"); $this->load->library('session'); $this->session->set_flashdata('$my_var' , $data["id"]); redirect('/xmlreceive/r_data/'); } } ?>
this second controller xmlreceive.php
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class xmlreceive extends ci_controller { public function r_data() { $this->load->library('session'); $my_var = $this->session->flashdata('$my_var'); echo $my_var; } } ?>
this view taking input in test box
<html> <form method="post" action="<?php echo base_url();?>xmlpost/index"> <input type="text" name="id" /> <input type="submit" value="submit"/> </form> </html>
what trying take input view , hold in controller xmlpost.php , pass controller xmlreceive.php. working fine.
the problem when put xml data in text box in xmlreceive.php controller data without xml tag if in insert
<?xml version="1.0" encoding="utf-8"?> <?adf version="1.0"?> <adf> <prospect><id sequence="1" source="xxxs">37</id> </adf>
in text box , click submit 37 in xmlreceive.php want output xml tags i.e. way inserted
how can solve problem
the reason xml not showing because browser assumes using html, able view in browser need tell otherwise i.e.:
header('content-type: text/xml');
(note: example you've given above error because there isn't closing tag <prospect>
).
the other option echo content inside htmlentities()
, use html_entity_decode()
convert content html xml when want write file.
hope helps!
Comments
Post a Comment