本文整理汇总了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']);
}
}
示例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();
}
示例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();
}
示例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();
}
示例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");
}
}
示例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);
}
示例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);
}
}
}
示例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("Значение","Товар");
}
示例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()));
}
}
}
示例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();
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
}