protected function saveXml(SimpleXMLElement $xml, $path) { $dom = new \DOMDocument("1.0"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xml->asXML()); $this->writeFile($path, $dom->saveXML(), true, true); }
/** * handles form for creating empty module * * @param $key Identifier of connection (connected device ID) * @param $configParams * @param $postVals * * @return int */ public function handleCreateEmptyModuleForm($key, $configParams, $postVals) { $name = $postVals['name']; $namespace = $postVals['namespace']; $res = 0; $xmlTree = new \SimpleXMLElement('<' . $name . '></' . $name . '>'); $xmlTree->addAttribute('xmlns', $namespace); $xmlTree->registerXPathNamespace('xc', 'urn:ietf:params:xml:ns:netconf:base:1.0'); $xmlTree->addAttribute("xc:operation", "create", "urn:ietf:params:xml:ns:netconf:base:1.0"); $createString = "\n" . str_replace('<?xml version="1.0"?' . '>', '', $xmlTree->asXML()); try { $res = $this->executeEditConfig($key, $createString, $configParams['source']); if ($res == 0) { $this->container->get('request')->getSession()->getFlashBag()->add('success', "New module was created."); } } catch (\ErrorException $e) { $this->logger->warn('Could not create empty module.', array('error' => $e->getMessage(), 'xml' => $createString)); $this->container->get('request')->getSession()->getFlashBag()->add('error', "Could not create empty module. Error: " . $e->getMessage()); } return $res; }