当前位置: 首页>>代码示例>>PHP>>正文


PHP SimpleXmlElement::addChild方法代码示例

本文整理汇总了PHP中SimpleXmlElement::addChild方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXmlElement::addChild方法的具体用法?PHP SimpleXmlElement::addChild怎么用?PHP SimpleXmlElement::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleXmlElement的用法示例。


在下文中一共展示了SimpleXmlElement::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addXmlIdentifier

 /**
  * Add to service xml description identifier by REST info
  * @param SimpleXmlElement $xmlProduct
  * @param array $serviceRest
  */
 private function addXmlIdentifier($xmlProduct, $serviceRest) {
     if($serviceRest['1c_id'] != null ) {
         $xmlProduct->addChild("Ид", $serviceRest['1c_id']); 
     } else {
         $xmlProduct->addChild("Ид", $serviceRest['servicename']); 
     }
 }
开发者ID:Wasage,项目名称:werpa,代码行数:12,代码来源:ServicesController.php

示例2: arrayToXml

 /**
  * arrayToXml
  *
  * @param  string $array        Array to convert to xml
  * @param  string $rootNodeName Name of the root node
  * @param  string $xml          SimpleXmlElement
  * @return string $asXml        String of xml built from array
  */
 public static function arrayToXml($array, $rootNodeName = 'data', $xml = null, $charset = null)
 {
     if ($xml === null) {
         $xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>");
     }
     foreach ($array as $key => $value) {
         $key = preg_replace('/[^a-z]/i', '', $key);
         if (is_array($value) && !empty($value)) {
             $node = $xml->addChild($key);
             foreach ($value as $k => $v) {
                 if (is_numeric($v)) {
                     unset($value[$k]);
                     $node->addAttribute($k, $v);
                 }
             }
             self::arrayToXml($value, $rootNodeName, $node, $charset);
         } else {
             if (is_int($key)) {
                 $xml->addChild($value, 'true');
             } else {
                 $charset = $charset ? $charset : 'utf-8';
                 if (strcasecmp($charset, 'utf-8') !== 0 && strcasecmp($charset, 'utf8') !== 0) {
                     $value = iconv($charset, 'UTF-8', $value);
                 }
                 $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
                 $xml->addChild($key, $value);
             }
         }
     }
     return $xml->asXML();
 }
开发者ID:marekk,项目名称:doctrine1,代码行数:39,代码来源:Xml.php

示例3: arrayToXml

 /**
  * arrayToXml
  *
  * @param  string $array        Array to convert to xml    
  * @param  string $rootNodeName Name of the root node
  * @param  string $xml          SimpleXmlElement
  * @return string $asXml        String of xml built from array
  */
 public static function arrayToXml($array, $rootNodeName = 'data', $xml = null)
 {
     if ($xml === null) {
         $xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>");
     }
     foreach ($array as $key => $value) {
         $key = preg_replace('/[^a-z]/i', '', $key);
         if (is_array($value) && !empty($value)) {
             $node = $xml->addChild($key);
             foreach ($value as $k => $v) {
                 if (is_numeric($v)) {
                     unset($value[$k]);
                     $node->addAttribute($k, $v);
                 }
             }
             self::arrayToXml($value, $rootNodeName, $node);
         } else {
             if (is_int($key)) {
                 $xml->addChild($value, 'true');
             } else {
                 $value = htmlentities($value);
                 $xml->addChild($key, $value);
             }
         }
     }
     return $xml->asXML();
 }
开发者ID:swk,项目名称:bluebox,代码行数:35,代码来源:Xml.php

示例4: arrayToXml

 /**
  * arrayToXml
  *
  * @param  string $array        Array to convert to xml    
  * @param  string $rootNodeName Name of the root node
  * @param  string $xml          SimpleXmlElement
  * @return string $asXml        String of xml built from array
  */
 public function arrayToXml($array, $rootNodeName = 'data', $xml = null)
 {
     if ($xml === null) {
         $xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>");
     }
     foreach ($array as $key => $value) {
         if (is_array($value)) {
             $node = $xml->addChild($key);
             $this->arrayToXml($value, $rootNodeName, $node);
         } else {
             $value = htmlentities($value);
             $xml->addChild($key, $value);
         }
     }
     return $xml->asXML();
 }
开发者ID:kirvin,项目名称:the-nerdery,代码行数:24,代码来源:Xml.php

示例5: addOrderProps

 /**
  * Add props to order, specified for website.
  * @param SimpleXmlElement $document
  * @param array $salesOrderRest
  */
 protected function addOrderProps($document, $salesOrderRest)
 {
     $documentProps = $document->addChild("ЗначенияРеквизитов");
     $documentProp = $documentProps->addChild("ЗначениеРеквизита");
     $documentProp->addChild("Наименование", "Номер по 1С");
     $documentProp->addChild("Значение", $salesOrderRest['fromsite']);
     if ($salesOrderRest['sostatus'] == "Created") {
         $documentProp = $documentProps->addChild("ЗначениеРеквизита");
         $documentProp->addChild("Наименование", "Проведен");
         $documentProp->addChild("Значение", "false");
     }
     if ($salesOrderRest['sostatus'] == "Approved") {
         $documentProp = $documentProps->addChild("ЗначениеРеквизита");
         $documentProp->addChild("Наименование", "Проведен");
         $documentProp->addChild("Значение", "true");
     }
     if ($salesOrderRest['sostatus'] == "Delivered") {
         $documentProp = $documentProps->addChild("ЗначениеРеквизита");
         $documentProp->addChild("Наименование", "Проведен");
         $documentProp->addChild("Значение", "true");
         $documentProp = $documentProps->addChild("ЗначениеРеквизита");
         $documentProp->addChild("Наименование", "Номер оплаты по 1С");
         $documentProp->addChild("Значение", $salesOrderRest['salesorder_no']);
     }
     if ($salesOrderRest['sostatus'] == "Cancelled") {
         $documentProp = $documentProps->addChild("ЗначениеРеквизита");
         $documentProp->addChild("Наименование", "Отменен");
         $documentProp->addChild("Значение", "true");
         $documentProp = $documentProps->addChild("ЗначениеРеквизита");
         $documentProp->addChild("Наименование", "Проведен");
         $documentProp->addChild("Значение", "false");
     }
 }
开发者ID:DeliveryPLANET,项目名称:vTiger,代码行数:38,代码来源:WebsiteSalesOrderController.php

示例6: addXmlAccountId

 /**
  * Add to account xml description identifier.
  * @param SimpleXmlElement $account
  * @param array $accountRest
  */
 private function addXmlAccountId($account, $accountRest) {
     $accountId = $accountRest['1c_id'];
     if($accountId == null) {
         $accountId = $accountRest['accountname'];
     }
     $account->addChild("Ид", $accountId);
 }
开发者ID:Wasage,项目名称:werpa,代码行数:12,代码来源:AccountsController.php

示例7: _serializeRecurser

 protected function _serializeRecurser($graphNodes, SimpleXmlElement $xmlNode)
 {
     // @todo find a better way to handle concurrency.. if no clone, _position in node gets messed up
     if ($graphNodes instanceof Zend_Tool_Project_Structure_Node) {
         $graphNodes = clone $graphNodes;
     }
     foreach ($graphNodes as $graphNode) {
         if ($graphNode->isDeleted()) {
             continue;
         }
         $nodeName = $graphNode->getContext()->getName();
         $nodeName[0] = strtolower($nodeName[0]);
         $newNode = $xmlNode->addChild($nodeName);
         $reflectionClass = new ReflectionClass($graphNode->getContext());
         if ($graphNode->isEnabled() == false) {
             $newNode->addAttribute('enabled', 'false');
         }
         foreach ($graphNode->getPersistentParameters() as $paramName => $paramValue) {
             $newNode->addAttribute($paramName, $paramValue);
         }
         if ($graphNode->hasChildren()) {
             self::_serializeRecurser($graphNode, $newNode);
         }
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:25,代码来源:Xml.php

示例8: addXmlProps

 /**
  * Add props to xml description, specified for product. Need to identificate
  * inventory as product in One Es.
  * @param SimpleXmlElement $xmlProduct
  */
 private function addXmlProps($xmlProduct) {
     $props = $xmlProduct->addChild("ЗначенияРеквизитов");
     $prop = $props->addChild("ЗначениеРеквизита");
     $prop->addChild("Наименование","ВидНоменклатуры");
     $prop->addChild("Значение","Товар");
     $prop = $props->addChild("ЗначениеРеквизита");
     $prop->addChild("Наименование","ТипНоменклатуры");
     $prop->addChild("Значение","Товар");
 }
开发者ID:Wasage,项目名称:werpa,代码行数:14,代码来源:ProductsController.php

示例9: afterStep

 /**
  * afterStep
  *
  * @param mixed $event
  */
 public function afterStep($event)
 {
     $code = $event->getTestResult()->getResultCode();
     if (TestResult::FAILED === $code) {
         if ($event->getTestResult()->hasException()) {
             $failureNode = $this->currentTestcase->addChild('failure', $event->getStep()->getKeyword() . " " . $event->getStep()->getText() . ":\n\n" . $event->getTestResult()->getException()->getMessage());
             $failureNode->addAttribute('type', \get_class($event->getTestResult()->getException()));
         }
     }
 }
开发者ID:vidarl,项目名称:behat-junit-formatter,代码行数:15,代码来源:JUnitFormatter.php

示例10: export

 /**
  * {@inheritdoc}
  */
 public function export(array $data)
 {
     $countriesElement = new \SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><countries/>");
     foreach ($data as $iso => $name) {
         $countryElement = $countriesElement->addChild('country');
         $countryElement->addChild('iso', $iso);
         $countryElement->addChild('name', $countryElement->ownerDocument->createCDATASection($name));
     }
     return $countriesElement->asXML();
 }
开发者ID:cybercog,项目名称:country-list,代码行数:13,代码来源:Xml.php

示例11: __call

 /**
  * Converts method calls into InboundXML verbs.
  *
  * @return SimpleXmlElement A SimpleXmlElement
  */
 public function __call($verb, array $args)
 {
     /** convert verbs input like-this-one to LikeThisOne **/
     $verb = preg_replace("/[-_]([a-z])/e", "ucfirst('\\1')", ucwords($verb));
     /** Let's first go check if the verb exists **/
     $this->_validateVerb(ucfirst($verb));
     /** Let's go validate nesting **/
     $this->_validateNesting(ucfirst($verb));
     list($noun, $attrs) = $args + array('', array());
     if (is_array($noun)) {
         list($attrs, $noun) = array($noun, '');
     }
     $child = empty($noun) ? $this->element->addChild(ucfirst($verb)) : $this->element->addChild(ucfirst($verb), $noun);
     foreach ($attrs as $name => $value) {
         /** Validation of verb attributes **/
         $this->_validateAttribute($name, $verb);
         $child->addAttribute($name, $value);
     }
     return new self($child);
 }
开发者ID:gecatalin,项目名称:telapi-php,代码行数:25,代码来源:InboundXML.php

示例12: hydrate

 /**
  * Populate the protected $_data SimpleXmlElement with the passed in array
  * Warning: no validation is done so you can end up with some crazy SimpleXmlElement objects
  * if you aren't careful passing in valid arrays.
  * 
  * The array keys may be camelCaseWords or dash-type-words. If they are camelCaseWords, they 
  * will be converted to dash-type-words for the SimpleXmlElement.
  * 
  * @param array $data
  * @param string $wrapper
  * @return void
  */
 public function hydrate(array $data, $wrapper)
 {
     $wrapper = SpreedlyCommon::camelToDash($wrapper);
     $xml = '<' . $wrapper . '/>';
     $xml = new SimpleXmlElement($xml);
     foreach ($data as $key => $value) {
         $key = SpreedlyCommon::camelToDash($key);
         $xml->addChild($key, $value);
     }
     $this->setData($xml);
 }
开发者ID:rbredow,项目名称:allyzabbacart,代码行数:23,代码来源:SpreedlyXmlObject.php

示例13: _asXml

 /**
  * Output as XML
  *
  * @param array $shellList The shell list.
  * @return void
  */
 protected function _asXml($shellList)
 {
     $shells = new SimpleXmlElement('<shells></shells>');
     foreach ($shellList as $command) {
         $callable = $command;
         $shell = $shells->addChild('shell');
         $shell->addAttribute('name', $command);
         $shell->addAttribute('call_as', $callable);
         $shell->addAttribute('help', $callable . ' -h');
     }
     $this->out($shells->saveXML());
 }
开发者ID:coretyson,项目名称:coretyson,代码行数:18,代码来源:CommandListShell.php

示例14: arrayToXml

 public static function arrayToXml(\SimpleXMLElement $object = null, $data = array())
 {
     foreach ($data as $key => $value) {
         if (is_object($value)) {
             $value = ArrayUtilsVTT::objectToArray($value);
         }
         if ($load = simplexml_load_string($value)) {
             $keyXMl = null;
             $doc = new \DOMDocument();
             $doc->loadXML($object->asXML());
             $appendXml = $doc->createDocumentFragment();
             $keyXMl = is_numeric($key) ? StringUtilsVTT::ToPluralString($load->children()->getName()) : $key;
             $stringXml = "<{$keyXMl}>";
             foreach ($load as $item) {
                 $stringXml .= $item->asXML();
             }
             $stringXml .= "</{$keyXMl}>";
             $appendXml->appendXML($stringXml);
             $doc->documentElement->appendChild($appendXml);
             $object = new \SimpleXmlElement($doc->saveXML());
             continue;
         }
         if (is_array($value)) {
             if (!is_numeric($key)) {
                 $new_object = $object->addChild($key);
             } else {
                 $new_object = $object->addChild($object->getName());
             }
             self::arrayToXml($new_object, $value, false);
         } else {
             if (!is_numeric($key)) {
                 $object->addChild($key, $value);
             } else {
                 $object->addChild($object->getName(), $value);
             }
         }
     }
     return $object;
 }
开发者ID:scorpionx,项目名称:vtt-bundle,代码行数:39,代码来源:XmlUtilsVTT.php

示例15: afterScenario

 /**
  * afterScenario
  *
  * @param mixed $event
  */
 public function afterScenario(AfterScenarioTested $event)
 {
     $this->testcaseTimer->stop();
     $code = $event->getTestResult()->getResultCode();
     $testResultString = array(TestResult::PASSED => 'passed', TestResult::SKIPPED => 'skipped', TestResult::PENDING => 'pending', TestResult::FAILED => 'failed');
     $this->testsuiteStats[$code]++;
     $this->currentTestcase->addAttribute('time', \round($this->testcaseTimer->getTime(), 3));
     $this->currentTestcase->addAttribute('status', $testResultString[$code]);
     if ($this->lastStepFailure) {
         $failureNode = $this->currentTestcase->addChild('failure', $this->lastStepFailureException->getMessage());
         $failureNode->addAttribute('message', $this->lastStepFailure);
     }
 }
开发者ID:dizzy7,项目名称:behat-junit-formatter,代码行数:18,代码来源:JUnitFormatter.php


注:本文中的SimpleXmlElement::addChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。