codeigniter - Getting information from .xml -


i have codeigniter library use load xml file

using simplexml_load_file();

how ever can cdata information on xml file cannot name="" xml

how can correct name="" xml

<file name="controllers/test.php">

full xml

<?xml version="1.0" encoding="utf-8" ?>  <modification>     <file name="controllers/test.php"> <!-- need name=""-->         <operation>             <search><![cdata[class test extends ci_controller {]]></search>             <add position="after"><![cdata[public function __construct() {}]]></add>         </operation>     </file> </modification> 

var dump of simplexml_load_file()

object(simplexmlelement)[16]   public 'file' =>      object(simplexmlelement)[17]       public '@attributes' =>          array (size=1)           'name' => string 'controllers/test.php' (length=20)       public 'operation' =>          object(simplexmlelement)[18]           public 'search' =>              object(simplexmlelement)[19]               ...           public 'add' =>              object(simplexmlelement)[20]               ... 

my library

<?php  class mod_xml {      public function __construct() {         $this->run();     }      public function run() {         $file = apppath . 'third_party/mods/mods_test.xml';          $x = simplexml_load_file($file);          var_dump($x);          // should how <file name="get content">          //$name = ;          $search_for_code = $x->file->operation->search;          $add = $x->file->operation->add;          $get_the_main_file_contents = file_get_contents(apppath . 'controllers/test.php');          $new_file_data = str_replace("$search_for_code", "$add", $get_the_main_file_contents);          if (!file_exists(apppath . 'controllers/backup/test.php')) {             @copy(apppath . 'controllers/test.php', apppath . 'controllers/backup/test.php');         }          if(strpos($get_the_main_file_contents, "$search_for_code") !== false){             file_put_contents(apppath . 'controllers/test.php', $new_file_data);         }     } } 

found out how simple solution

$file = apppath . 'third_party/mods/mods_test.xml';  $x = simplexml_load_file($file);  echo $x->file['name']; 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -