/** * @return string */ protected function _getFlatData() { $this->_xml = new XmlElement('<config/>'); foreach ($this->_collection as $item) { /** @var $item \Mage_Core_Model_Config_Data */ $path = str_replace('/', self::SLASH_REPLACEMENT, $item->getPath()); if (isset($this->_xml->{$path})) { $nodePath = $this->_xml->{$path}; } else { $nodePath = $this->_xml->addChild($path); } if (isset($nodePath->{$item->getScope()})) { $nodeScope = $nodePath->{$item->getScope()}; } else { $nodeScope = $nodePath->addChild($item->getScope()); } $valueChild = $nodeScope->addChild('value', $item->getValue()); $valueChild->addAttribute('scope_id', $item->getScopeId()); } return $this->_xml->asNiceXml(); }
public static function toXml($data, $parent = 'root') { if (!$parent instanceof XmlNode) { $parent = new XmlElement((string) $parent); } switch (true) { case is_array($data): case is_object($data): $parent->setAttribute('type', 'structure'); foreach ($data as $key => $value) { if (is_int($key)) { $key = 'element'; } $node = new XmlElement($key); $parent->addChild($node); Xml::toXml($value, $node); } break; case is_bool($data): $parent->setAttribute('type', 'boolean'); $parent->addChild(new XmlText($data ? 'true' : 'false')); break; case is_int($data): $parent->setAttribute('type', 'integer'); $parent->addChild(new XmlText($data)); break; case is_string($data): $parent->setAttribute('type', 'string'); $parent->addChild(new XmlText($data)); break; case is_float($data): $parent->setAttribute('type', 'float'); $parent->addChild(new XmlText($data)); break; case is_double($data): $parent->setAttribute('type', 'double'); $parent->addChild(new XmlText($data)); break; case is_null($data): //break; //break; default: $parent->addChild(new XmlText($data)); break; } return $parent; }