本文整理匯總了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' => ' ')));
}