本文整理汇总了PHP中XML::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP XML::encode方法的具体用法?PHP XML::encode怎么用?PHP XML::encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML
的用法示例。
在下文中一共展示了XML::encode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __set
/**
* This function sets the value for the specified key.
*
* @access public
* @override
* @param string $key the name of the property
* @param mixed $value the value of the property
* @throws Throwable_InvalidProperty_Exception indicates that the specified property is
* either inaccessible or undefined
*/
public function __set($key, $value)
{
switch ($key) {
case 'value':
if (is_object($value) and $value instanceof SimpleXMLElement) {
$value = $value->asXML();
} else {
if (is_array($value)) {
$value = XML::encode($value, TRUE);
}
}
$this->model->{$this->metadata['field']} = $value;
break;
default:
throw new Throwable_InvalidProperty_Exception('Message: Unable to set the specified property. Reason: Property :key is either inaccessible or undefined.', array(':key' => $key, ':value' => $value));
break;
}
}
示例2: testDecodeEncode
public function testDecodeEncode()
{
$expected = "<?xml version=\"1.0\"?>\n" . "<User>\n" . " <Name>Joby Walker</Name>\n" . " <HasSkills>false</HasSkills>\n" . " <Locations>\n" . " <Location>\n" . " <Type>work</Type>\n" . " <City>Seattle</City>\n" . " </Location>\n" . " <Location>\n" . " <Type>home</Type>\n" . " <City>Seattle</City>\n" . " <Cats>2</Cats>\n" . " <Dogs/>\n" . " </Location>\n" . " </Locations>\n" . "</User>";
$this->assertEquals($expected, XML::encode(XML::decode($expected), null, array('declare' => true, 'offset' => ' ', 'depth' => -1)));
$this->assertEquals($expected, XML::encode(XML::decode($expected, array('StripContainer' => true)), 'User', array('declare' => true, 'offset' => ' ')));
}