Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Xml_insert extends CI_Controller {
- function index() {
- $this->load->model('xml_insert_model');
- $data['rows'] = $this->xml_insert_model->getAll();
- $this->load->view('xml_insert_view', $data);
- }
- function insert() {
- $this->load->model('xml_insert_model');
- $data['rows'] = $this->xml_insert_model->getAll();
- foreach ($data['rows'] as $r) {
- $path1 = $r->xml_file_path;
- $xml = simplexml_load_file($path1);
- $newAct = $_POST['activity'];
- $root = $xml->firstChild;
- $newElement = $xml->createElement('activity');
- $root->appendChild($newElement);
- $newText = $xml->createTextNode($newAct);
- $newElement->appendChild($newText);
- $xml->save('$path1');
- $this->index();
- }
- }
- }
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Document</title>
- </head>
- <body>
- <?php foreach ($rows as $r): ?>
- <?php
- $path1 = $r->xml_file_path;
- $xml = simplexml_load_file($path1);
- ?>
- <?php foreach ($xml->children() as $activity) : ?>
- <?php echo "Activity : " . $activity . " <br />"; ?>
- <?php endforeach; ?>
- <?php endforeach; ?>
- <form name="input" action="index.php/xml_insert/insert" method="post">
- insert activity:
- <input type="text" name="activity"/>
- <input type="submit" value="send"/>
- </form>
- </body>
- </html>
- <?php
- class Xml_insert_model extends CI_Model
- {
- function getAll()
- {
- $q = $this->db->get("XML");
- if ($q->num_rows > 0) {
- foreach ($q->result() as $row) {
- $data[] = $row;
- }
- return $data;
- }
- }
- }
- <?xml version="1.0"?>
- <list>
- <activity>swimming</activity>
- <activity>running</activity>
- <activity>Jogging</activity>
- <activity>Theatre</activity>
- <activity>Programming</activity>
- <activity>driving</activity>
- <activity>eating</activity>
- </list>
- $xml = new DomDocument();
- $xml->load($path1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement