本文整理汇总了PHP中SimpleXMLElement::addChild方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::addChild方法的具体用法?PHP SimpleXMLElement::addChild怎么用?PHP SimpleXMLElement::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format
/**
* Encodes the given data to a specific data format.
*
* @param array $data
* @param \SimpleXMLElement $xml
*
* @return string
*/
public function format(array $data, $xml = null)
{
if (!isset($xml)) {
$xml = new \SimpleXMLElement('<Response/>');
}
foreach ($data as $key => $value) {
if (is_numeric($key)) {
if (!is_array($value)) {
$key = get_class($value);
} else {
$key = 'Data';
}
}
if (is_array($value)) {
$this->format($value, $xml->addChild($key));
} else {
if ($value instanceof ArrayableInterface) {
$this->format($value->toArray(), $xml->addChild($key));
} else {
$xml->addChild($key, $value);
}
}
}
return $xml->asXML();
}
示例2: __construct
/**
* Constructor
*/
public function __construct()
{
$this->_ci =& get_instance();
$this->_ci->load->library(array("core/string/string_core", "cache"));
$this->_kml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" . "</kml>");
$this->_kml->addChild("Document");
}
示例3: indexAction
public function indexAction()
{
$url = $this->getRequest()->getParam('url');
$xmlString = '<?xml version="1.0" standalone="yes"?><response></response>';
$xml = new SimpleXMLElement($xmlString);
if (strlen($url) < 1) {
$xml->addChild('status', 'failed no url passed');
} else {
$shortid = $this->db->fetchCol("select * from urls where url = ?", $url);
$config = Zend_Registry::getInstance();
$sh = $config->get('configuration');
if ($shortid[0]) {
$hex = dechex($shortid[0]);
$short = $sh->siteroot . $hex;
} else {
//if not insert then return the id
$data = array('url' => $url, 'createdate' => date("Y-m-d h:i:s"), 'remoteip' => Pandamp_Lib_Formater::getRealIpAddr());
$insert = $this->db->insert('urls', $data);
$id = $this->db->lastInsertId('urls', 'id');
$hex = dechex($id);
$short = $sh->siteroot . $hex;
}
$xml->addChild('holurl', $short);
$xml->addChild('status', 'success');
}
$out = $xml->asXML();
//This returns the XML xmlreponse should be key value pairs
$this->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($out);
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
}
示例4: transform
/**
* @param DecoderInterface $decoder
*
* @return string
*/
public function transform(DecoderInterface $decoder)
{
$xml = new \SimpleXMLElement('<xml/>');
foreach ($decoder->getData() as $key => $value) {
if (is_array($value)) {
if (is_numeric($key)) {
$items = $xml->addChild('items');
$item = $items->addChild('item');
} else {
$item = $xml->addChild($key);
}
foreach ($value as $k => $v) {
if (is_array($v)) {
continue;
}
$item->addChild($k, $v);
}
continue;
}
$xml->addChild($key, $value);
}
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
return $dom->saveXML();
}
示例5: _recursiveXmlEncode
protected static function _recursiveXmlEncode($valueToEncode, $rootNodeName = 'data', &$xml = null)
{
if (null == $xml) {
$xml = new SimpleXMLElement('<' . $rootNodeName . '/>');
}
foreach ($valueToEncode as $key => $value) {
if (is_numeric($key)) {
$key = $rootNodeName;
}
if ($key == self::XML_ATTRIBUTES) {
foreach ($value as $attrName => $attrValue) {
$xml->addAttribute($attrName, $attrValue);
}
} else {
// Filter non valid XML characters
$key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key);
if (is_array($value)) {
$node = self::_isAssoc($value) ? $xml->addChild($key) : $xml;
self::_recursiveXmlEncode($value, $key, $node);
} else {
$value = htmlspecialchars($value, null, 'UTF-8');
// $value = htmlentities($value, null, 'UTF-8');
$xml->addChild($key, $value);
}
}
}
return $xml;
}
示例6: _convertToXml
/**
* Populate $xml with entries from $data array|DataObject.
*
* @param DataObject|array $data
* @param \SimpleXMLElement $xml
*/
private function _convertToXml($data, \SimpleXMLElement &$xml, $path = '')
{
if ($data instanceof DataObject) {
$data = $data->getData();
}
foreach ($data as $key => $value) {
if (is_int($key)) {
/* this is array nodes with integer indexes */
$name = $this->_namingStrategy->getNameForKey($key, $path);
$newPath = $path . INamingStrategy::PS . $name;
$arrayNode = $xml->addChild($name);
if (is_array($value)) {
$this->_convertToXml($value, $arrayNode, $newPath);
} elseif ($value instanceof \Flancer32\Lib\DataObject) {
$this->_convertToXml($value, $arrayNode, $newPath);
} else {
throw new \Exception('Data in array nodes should not be simple, array or DataObject is expected.');
}
} else {
/* this is XML node, not array subnode */
$name = $this->_namingStrategy->getNameForKey($key, $path);
$newPath = $path . INamingStrategy::PS . $name;
if (is_array($value)) {
$subnode = $xml->addChild($name);
$this->_convertToXml($value, $subnode, $newPath);
} elseif ($value instanceof \Flancer32\Lib\DataObject) {
$subnode = $xml->addChild($name);
$this->_convertToXml($value, $subnode, $newPath);
} else {
$xml->addChild($name, htmlspecialchars($value));
}
}
}
}
示例7: serializeToXml
public function serializeToXml()
{
$strXml = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<LiveChannelConfiguration>
</LiveChannelConfiguration>
EOF;
$xml = new \SimpleXMLElement($strXml);
if (isset($this->description)) {
$xml->addChild('Description', $this->description);
}
if (isset($this->status)) {
$xml->addChild('Status', $this->status);
}
$node = $xml->addChild('Target');
$node->addChild('Type', $this->type);
if (isset($this->fragDuration)) {
$node->addChild('FragDuration', $this->fragDuration);
}
if (isset($this->fragCount)) {
$node->addChild('FragCount', $this->fragCount);
}
if (isset($this->playListName)) {
$node->addChild('PlayListName', $this->playListName);
}
return $xml->asXML();
}
示例8: generate_xml
public function generate_xml($root, $tag_configuration)
{
$xml = new SimpleXMLElement('<oml:' . $root . ' xmlns:oml="http://openml.org/openml"/>');
// first obtain the indices
$indices = array();
foreach ($tag_configuration as $key => $value) {
$indices = array_merge($indices, array_keys($value));
}
sort($indices);
foreach ($indices as $index) {
foreach ($tag_configuration as $tag_type => $tags) {
foreach ($tags as $tag_index => $tag_name) {
if ($tag_index == $index) {
if ($this->CI->input->post($tag_name)) {
if ($tag_type == 'csv') {
if (is_array($this->CI->input->post($tag_name))) {
$values_exploded = $this->CI->input->post($tag_name);
} else {
$values_exploded = explode(',', $this->CI->input->post($tag_name));
}
foreach ($values_exploded as $value) {
$xml->addChild('oml:' . $tag_name, $value);
}
} else {
// TODO: add support for plain and array.
$value = $this->CI->input->post($tag_name);
$xml->addChild('oml:' . $tag_name, str_replace('&', '&', htmlentities($value)));
}
}
}
}
}
}
return $xml->asXML();
}
示例9: _ConstructPostData
protected function _ConstructPostData($postData)
{
$billingDetails = $this->GetBillingDetails();
$qbXML = new SimpleXMLElement('<?qbmsxml version="2.0"?><QBMSXML />');
$signOnDesktop = $qbXML->addChild('SignonMsgsRq')->addChild('SignonDesktopRq');
$signOnDesktop->addChild('ClientDateTime', date('Y-m-d\TH:i:s'));
$signOnDesktop->addChild('ApplicationLogin', $this->GetValue('ApplicationLogin'));
$signOnDesktop->addChild('ConnectionTicket', $this->GetValue('ConnectionTicket'));
$signOnDesktop->addChild('Language', 'English');
$signOnDesktop->addChild('AppID', $this->GetValue('AppID'));
$signOnDesktop->addChild('AppVer', '1.0');
$cardChargeRequest = $qbXML->addChild('QBMSXMLMsgsRq')->addChild('CustomerCreditCardChargeRq');
$cardChargeRequest->addChild('TransRequestID', $this->GetCombinedOrderId());
$cardChargeRequest->addChild('CreditCardNumber', $postData['ccno']);
$cardChargeRequest->addChild('ExpirationMonth', $postData['ccexpm']);
$cardChargeRequest->addChild('ExpirationYear', $postData['ccexpy']);
$cardChargeRequest->addChild('IsECommerce', 'true');
$cardChargeRequest->addChild('Amount', $this->GetGatewayAmount());
$cardChargeRequest->addChild('NameOnCard', isc_substr($postData['name'], 0, 30));
$cardChargeRequest->addChild('CreditCardAddress', isc_substr($billingDetails['ordbillstreet1'], 0, 30));
$cardChargeRequest->addChild('CreditCardPostalCode', isc_substr($billingDetails['ordbillzip'], 0, 9));
$cardChargeRequest->addChild('SalesTaxAmount', $this->GetTaxCost());
$cardChargeRequest->addChild('CardSecurityCode', $postData['cccvd']);
return $qbXML->asXML();
}
示例10: arrayToXml
/**
* Преобразовать PHP-массив в XML
*
* Метод также используется в PHPUnit тестах сервисов
*
* @param array $data
* @param \SimpleXMLElement $xmlBlank
* @param string $itemName
*/
public function arrayToXml($data, \SimpleXMLElement &$xmlBlank, $itemName = 'item')
{
foreach ($data as $key => $value) {
if (is_array($value) || is_object($value)) {
if (!is_numeric($key)) {
$subnode = $xmlBlank->addChild((string) $key);
$this->arrayToXml($value, $subnode, $itemName);
} else {
$subnode = $xmlBlank->addChild($itemName);
$this->arrayToXml($value, $subnode, $itemName);
}
} else {
$val = $value;
if (is_bool($value)) {
$val = $value ? 'true' : 'false';
} else {
if (is_int($value)) {
$val = (int) $value;
} else {
$val = htmlspecialchars("{$value}");
}
}
if (!is_numeric($key)) {
$xmlBlank->addChild("{$key}", $val);
} else {
$xmlBlank->addChild($itemName, $val);
}
}
}
}
示例11: output
/**
* Generate the sitemap file and replace any output with the valid XML of the sitemap
*
* @param string $type Type of sitemap to be generated. Use 'urlset' for a normal sitemap. Use 'sitemapindex' for a sitemap index file.
* @access public
* @return void
*/
public function output($type = 'urlset')
{
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><' . $type . '/>');
$xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
if ($type == 'urlset') {
foreach ($this->urls as $url) {
$child = $xml->addChild('url');
$child->addChild('loc', strtolower($url->loc));
if (isset($url->lastmod)) {
$child->addChild('lastmod', $url->lastmod);
}
if (isset($url->changefreq)) {
$child->addChild('changefreq', $url->changefreq);
}
if (isset($url->priority)) {
$child->addChild('priority', number_format($url->priority, 1));
}
}
} elseif ($type == 'sitemapindex') {
foreach ($this->urls as $url) {
$child = $xml->addChild('sitemap');
$child->addChild('loc', strtolower($url->loc));
if (isset($url->lastmod)) {
$child->addChild('lastmod', $url->lastmod);
}
}
}
$this->output->set_content_type('application/xml')->set_output($xml->asXml());
}
示例12: buildBundlePackage
static function buildBundlePackage($bundleName, $moduleList, $manifestData, $buildPath)
{
$fileName = $bundleName . '.zip';
if (is_file($buildPath . '/' . $fileName)) {
unlink($buildPath . '/' . $fileName);
}
$tmpPath = "build/{$bundleName}";
@mkdir($tmpPath);
foreach ($moduleList as $moduleName) {
self::buildModulePackage($moduleName, $tmpPath);
}
$manifestDoc = new SimpleXMLElement("<?xml version='1.0'?><module/>");
$manifestDoc->addChild('name', $bundleName);
$manifestDoc->addChild('version', $manifestData['version']);
$manifestDoc->addChild('modulebundle', 'true');
$xmlDependencies = $manifestDoc->addChild('dependencies');
$xmlDependencies->addChild('vtiger_version', $manifestData['vtiger_version']);
$xmlDependencies->addChild('vtiger_max_version', $manifestData['vtiger_max_version']);
$xmlModuleList = $manifestDoc->addChild('modulelist');
$index = 1;
foreach ($moduleList as $moduleName) {
$xmlModule = $xmlModuleList->addChild('dependent_module');
$xmlModule->addChild('name', $moduleName);
$xmlModule->addChild('install_sequence', $index);
$xmlModule->addChild('filepath', $moduleName . '.zip');
$index++;
}
$manifestDoc->asXML($tmpPath . '/' . 'manifest.xml');
$zip = new Vtiger_Zip($buildPath . '/' . $fileName);
$zip->addFile($tmpPath . '/' . 'manifest.xml', 'manifest.xml');
foreach ($moduleList as $module) {
$zip->addFile($tmpPath . '/' . $module . '.zip', $module . '.zip');
}
$zip->save();
}
示例13: arrayToXml
public static function arrayToXml(array $data, \SimpleXMLElement $xml, $parentKey = null, $keyFilterCallback = null)
{
foreach ($data as $k => $v) {
if (!is_numeric($k) && is_callable($keyFilterCallback)) {
$k = call_user_func($keyFilterCallback, $k);
}
if (is_array($v)) {
if (!is_numeric($k)) {
self::arrayToXml($v, $xml->addChild($k), $k, $keyFilterCallback);
} else {
self::arrayToXml($v, $xml->addChild(Inflector::singularize($parentKey)), null, $keyFilterCallback);
}
} else {
if (!is_numeric($k)) {
$xml->addChildWithCDATA($k, $v);
} else {
if (!is_null($parentKey)) {
$xml->addChildWithCDATA(Inflector::singularize($parentKey), $v);
} else {
throw new \Exception("Array To xml forma error: invalid element name {$k}");
}
}
}
}
return $xml;
}
示例14: send
/**
* @param MessageInterface|Message $message
* @return mixed|void
* @throws RuntimeException
*/
public function send(MessageInterface $message)
{
$config = $this->getSenderOptions();
$serviceURL = "http://letsads.com/api";
$body = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><request></request>');
$auth = $body->addChild('auth');
$auth->addChild('login', $config->getUsername());
$auth->addChild('password', $config->getPassword());
$messageXML = $body->addChild('message');
$messageXML->addChild('from', $config->getSender());
$messageXML->addChild('text', $message->getMessage());
$messageXML->addChild('recipient', $message->getRecipient());
$client = new Client();
$client->setMethod(Request::METHOD_POST);
$client->setUri($serviceURL);
$client->setRawBody($body->asXML());
$client->setOptions(['sslverifypeer' => false, 'sslallowselfsigned' => true]);
try {
$response = $client->send();
} catch (Client\Exception\RuntimeException $e) {
throw new RuntimeException("Failed to send sms", null, $e);
}
try {
$responseXML = new \SimpleXMLElement($response->getBody());
} catch (\Exception $e) {
throw new RuntimeException("Cannot parse response", null, $e);
}
if ($responseXML->name === 'error') {
throw new RuntimeException("LetsAds return error (" . $responseXML->description . ')');
}
}
示例15: export
/** Returns the group/key config as XML.
* @return mixed
*/
public static function export()
{
$xml = new \SimpleXMLElement('<xml/>');
$groupConfigList = new Object\KeyValue\GroupConfig\Listing();
$groupConfigList->load();
$groupConfigItems = $groupConfigList->getList();
$groups = $xml->addChild('groups');
foreach ($groupConfigItems as $item) {
$group = $groups->addChild('group');
$group->addChild("id", $item->getId());
$group->addChild("name", $item->getName());
$group->addChild("description", $item->getDescription());
}
$keyConfigList = new Object\KeyValue\KeyConfig\Listing();
$keyConfigList->load();
$keyConfigItems = $keyConfigList->getList();
$keys = $xml->addChild('keys');
foreach ($keyConfigItems as $item) {
$key = $keys->addChild('key');
$id = $key->addChild('id', $item->getId());
$name = $key->addChild('name', $item->getName());
$description = $key->addChild('description', $item->getDescription());
$type = $key->addChild('type', $item->getType());
$unit = $key->addChild('unit', $item->getUnit());
$group = $key->addChild('group', $item->getGroup());
$possiblevalues = $key->addChild('possiblevalues', $item->getPossibleValues());
}
return $xml->asXML();
}