/** * testNamespacing method * * @access public * @return void */ function testNamespacing() { $node = new Xml('<xml></xml>'); $node->addNamespace('cake', 'http://cakephp.org'); $this->assertEqual($node->toString(), '<xml xmlns:cake="http://cakephp.org" />'); $this->assertTrue($node->removeNamespace('cake')); $this->assertEqual($node->toString(), '<xml />'); $node = new Xml('<xml xmlns:cake="http://cakephp.org" />'); $this->assertTrue($node->removeNamespace('cake')); $this->assertEqual($node->toString(), '<xml />'); $node->addNamespace('cake', 'http://cakephp.org'); $this->assertEqual($node->toString(), '<xml xmlns:cake="http://cakephp.org" />'); }
/** * Generate a XML for request * * @param string $method Name of method * @param array $params List of methods * @return string XML of request * @access protected */ function generateXML($method, $params = array()) { $query = array('methodCall' => array('methodName' => $method, 'params' => array())); if (!empty($params)) { $query['methodCall']['params']['param'] = array(); foreach ($params as $param) { $query['methodCall']['params']['param'][] = $this->_normalizeParam($param); } } $xml = new Xml($query, array('format' => 'tags', 'tags' => array('methodCall' => array('name' => 'methodCall')))); return $xml->toString(array('cdata' => false, 'header' => true)); }
function testToStringSlugging() { $array = array('Response' => array('OneKey' => 'foo', 'TwoKey' => array('bar', 'baz'))); $xml = new Xml($array, array('format' => 'tags')); $result = $xml->toString(array('cdata' => false)); $expected = '<response><one_key>foo</one_key><two_key>bar</two_key><two_key>baz</two_key></response>'; $this->assertEqual($result, $expected); }
/** * Serializes a model resultset into XML * * @param mixed $data The content to be converted to XML * @param array $options The data formatting options. For a list of valid options, see * XmlNode::__construct(). * @return string A copy of $data in XML format * @see XmlNode */ public function serialize($data, $options = array()) { $options += array('attributes' => false, 'format' => 'attributes'); $data = new Xml($data, $options); return $data->toString($options + array('header' => false)); }
/** *flash控制器. * *@param $type *@param $type_id */ public function index($type, $type_id = 0) { //$this->page_init(); if ($type == 'P') { $flash_info = $this->Flash->find("type = '{$type}'"); } else { $flash_info = $this->Flash->find("type = '{$type}' and type_id = {$type_id} "); } if (empty($flash_info)) { return; } $flash_info['Flash']['titlebgcolor'] = hexdec($flash_info['Flash']['titlebgcolor']); $flash_info['Flash']['titletextcolor'] = hexdec($flash_info['Flash']['titletextcolor']); $flash_info['Flash']['btntextcolor'] = hexdec($flash_info['Flash']['btntextcolor']); $flash_info['Flash']['btndefaultcolor'] = hexdec($flash_info['Flash']['btndefaultcolor']); $flash_info['Flash']['btnhovercolor'] = hexdec($flash_info['Flash']['btnhovercolor']); $flash_info['Flash']['btnfocuscolor'] = hexdec($flash_info['Flash']['btnfocuscolor']); $config['roundCorner'] = $flash_info['Flash']['roundcorner']; $config['autoPlayTime'] = $flash_info['Flash']['autoplaytime']; $config['isHeightQuality'] = $flash_info['Flash']['isheightquality']; //$config['normal'] = $flash_info['Flash']['normal']; $config['windowOpen'] = $flash_info['Flash']['windowopen']; $config['btnSetMargin'] = $flash_info['Flash']['btnsetmargin']; $config['btnDistance'] = $flash_info['Flash']['btndistance']; $config['titleBgColor'] = $flash_info['Flash']['titlebgcolor']; $config['titleTextColor'] = $flash_info['Flash']['titletextcolor']; $config['titleBgAlpha'] = $flash_info['Flash']['titlebgalpha']; $config['titleFont'] = $flash_info['Flash']['titlefont']; $config['titleMoveDuration'] = $flash_info['Flash']['titlemoveduration']; $config['btnAlpha'] = $flash_info['Flash']['btnalpha']; $config['btnTextColor'] = $flash_info['Flash']['btntextcolor']; $config['btnDefaultColor'] = $flash_info['Flash']['btndefaultcolor']; $config['btnHoverColor'] = $flash_info['Flash']['btnhovercolor']; $config['btnFocusColor'] = $flash_info['Flash']['btnfocuscolor']; $config['changImageMode'] = $flash_info['Flash']['changimagemode']; $config['isShowBtn'] = $flash_info['Flash']['isshowbtn']; $config['isShowTitle'] = $flash_info['Flash']['isshowtitle']; $config['scaleMode'] = $flash_info['Flash']['scalemode']; $config['transform'] = $flash_info['Flash']['transform']; $config['isShowAbout'] = $flash_info['Flash']['isshowabout']; if ($type == 'P') { $galleries = $this->ProductGallery->get_product_gallery($type_id); if (isset($galleries) && sizeof($galleries) > 0) { foreach ($galleries as $k => $v) { $flash_info['FlashImage'][$k]['image'] = $this->url($v['ProductGallery']['img_detail'], false); if (Configure::read('App.baseUrl')) { $flash_info['FlashImage'][$k]['image'] = str_replace('index.php/', '', $flash_info['FlashImage'][$k]['image']); } $flash_info['FlashImage'][$k]['flash_id'] = 1; $flash_info['FlashImage'][$k]['link'] = '#'; $flash_info['FlashImage'][$k]['title'] = ''; } } } elseif ($flash_info['FlashImage']) { foreach ($flash_info['FlashImage'] as $k => $v) { $flash_info['FlashImage'][$k]['image'] = $this->url($v['image'], false); if (Configure::read('App.baseUrl')) { $flash_info['FlashImage'][$k]['image'] = str_replace('index.php/', '', $flash_info['FlashImage'][$k]['image']); } if (isset($v['url']) && $v['url'] != '') { $flash_info['FlashImage'][$k]['link'] = $this->url($v['url'], false); unset($flash_info['FlashImage'][$k]['url']); } else { $flash_info['FlashImage'][$k]['link'] = '#'; } } } $channel = $flash_info['FlashImage']; // pr($channel); $flash = array('channel' => array('item' => $channel), 'config' => $config); $xml_array = array('data' => $flash); $xml = new Xml($xml_array, array('format' => 'tags')); // pr($xml_array); // pr($xml); $result = $xml->toString(array('cdata' => true)); // pr($result); $this->set('result', $result); // pr($flash); Configure::write('debug', 0); $this->layoutPath = 'xml'; $this->layout = 'default'; }
/** * testEscapeCharSerialization method * * @access public * @return void */ function testEscapeCharSerialization() { $xml = new Xml(array('text' => 'JavaScript & DHTML'), array('attributes' => false, 'format' => 'attributes')); $result = $xml->toString(false); $expected = '<std_class text="JavaScript & DHTML" />'; $this->assertEqual($expected, $result); }