<?php //traitement du xml $xml = simplexml_load_file("exemple.xml"); $xml2 = simplexml_load_file("exemple2.xml"); //$newNode = $xml2->movie->trivia; //$path = '/movies/movie/trivia/quotes/great-lines'; //$nodes = explode('/',$path); //$nodes = array_shift($nodes); $newNode = $xml2->xpath('/movies/movie/characters'); $xmlfinal = new simplexmlElement('<movies/>'); foreach ($newNode as $node) { foreach ($node as $subnode) { $xmlfinal->addChild('line', $subnode); } } $chainexml = $xmlfinal->asXML(); var_dump($chainexml);
/** * @param simplexmlElement $xml_obj */ private function _processXML($xml_obj) { $xml = $xml_obj->xpath('/datasets'); $datasets = $xml; //process each layout foreach ($datasets as $dataset) { $dataset = $dataset->dataset; /* Determine an action tag in all parent elements. * Action can be insert, update and delete * ->>> action = insert * Mean that we will try create new dataset with column definitions and insert rows in it * ->>> action = update (default) * Before loading the dataset, determin if same dataset exists with same name and key comdination. * If does exists, write new over existing * ->>> action = delete * Delete all that contains in dataset (values, definitions, properties and dataset) * NOTE: Parent level delete action is cascaded to all children elements */ if (!$dataset->action) { $dataset->action = 'update'; } if (in_array($dataset->action, array("update", "delete"))) { $this->__construct($dataset->dataset_name, $dataset->dataset_key); $this->dropDataset(); if ($dataset->action == "delete") { continue; } } if (in_array($dataset->action, array("insert", "update"))) { if ($dataset->dataset_name) { $this->__construct($dataset->dataset_name, $dataset->dataset_key); $this->createDataset($dataset->dataset_name, $dataset->dataset_key); } } // check creating if (!$this->dataset_id) { continue; } // set dataset definition if needed if ($dataset->dataset_definition && $dataset->dataset_definition->column_definition) { $definitions = array(); $i = 0; foreach ($dataset->dataset_definition->column_definition as $column_definition) { $definitions[$i]['name'] = (string) $column_definition->column_name; $definitions[$i]['type'] = (string) $column_definition->column_type; if ((int) $column_definition->column_sort_order) { $definitions[$i]['sort_order'] = (int) $column_definition->column_sort_order; } $i++; } $this->defineColumns($definitions); } // set dataset properties if needed if ($dataset->dataset_properties && $dataset->dataset_properties->dataset_property) { $properties = array(); foreach ($dataset->dataset_properties->dataset_property as $property) { $properties[(string) $property->dataset_property_name] = (string) $property->dataset_property_value; } $this->setDatasetProperties($properties); } // set column properties if needed if ($dataset->column_properties && $dataset->column_properties->column_property) { $properties = array(); foreach ($dataset->column_properties->column_property as $property) { $properties[(string) $property->column_property_name] = (string) $property->column_property_value; $this->setColumnProperties((string) $property->column_name, $properties); } } // operate with dataset rows if ($dataset->dataset_rows && $dataset->dataset_rows->dataset_row) { $row_values = array(); foreach ($dataset->dataset_rows->dataset_row as $row) { if ($row->cell) { foreach ($row->cell as $cell) { $row_values[][(string) $cell->column_name] = (string) $cell->value; } } } $this->addRows($row_values); } } // end of loop }