• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP SimpleXmlElement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: addChild

 /**
  * Add the node to a position under the tree
  *
  * @param \SimpleXmlElement|Element $node
  * @param Element $parent
  */
 public function addChild($node, $parent = null)
 {
     if ($node instanceof \SimpleXmlElement) {
         $name = $node->getName();
         $attributes = (array) $node->attributes();
         $content = trim((string) $node);
         $element = new Element($name, $attributes, $content);
         if (!$this->tree) {
             $this->tree = $element;
         } else {
             if (!$parent) {
                 $parent = $this->tree;
             }
             $parent->addChild($element);
         }
         // Add child elements recursive
         if ($node->count() > 0) {
             foreach ($node as $childNode) {
                 $this->addChild($childNode, $element);
             }
         }
     } else {
         if ($node instanceof Element) {
             if (!$this->tree) {
                 $this->tree = $node;
             } else {
                 if (!$parent) {
                     $parent = $this->tree;
                 }
                 $parent->addChild($node);
             }
         }
     }
 }
开发者ID:fewlines,项目名称:core,代码行数:40,代码来源:Tree.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: parseLinks

 /**
  * Parse Links
  *
  * Parses an XML file returned by a link resolver
  * and converts it to a standardised format for display
  *
  * @param string $xmlstr Raw XML returned by resolver
  *
  * @return array         Array of values
  */
 public function parseLinks($xmlstr)
 {
     $records = [];
     // array to return
     try {
         $xml = new \SimpleXmlElement($xmlstr);
     } catch (\Exception $e) {
         return $records;
     }
     $root = $xml->xpath("//ctx_obj_targets");
     $xml = $root[0];
     foreach ($xml->children() as $target) {
         $record = [];
         $record['title'] = (string) $target->target_public_name;
         $record['href'] = (string) $target->target_url;
         $record['service_type'] = (string) $target->service_type;
         if (isset($target->coverage->coverage_text)) {
             $coverageText =& $target->coverage->coverage_text;
             $record['coverage'] = (string) $coverageText->threshold_text->coverage_statement;
             if (isset($coverageText->embargo_text->embargo_statement)) {
                 $record['coverage'] .= ' ' . (string) $coverageText->embargo_text->embargo_statement;
                 $record['embargo'] = (string) $coverageText->embargo_text->embargo_statement;
             }
         }
         if (isset($target->coverage)) {
             $record['coverage_details'] = json_decode(json_encode($target->coverage), true);
         }
         array_push($records, $record);
     }
     return $records;
 }
开发者ID:bbeckman,项目名称:NDL-VuFind2,代码行数:41,代码来源:Sfx.php


示例4: fetch

 public function fetch($params)
 {
     $feed = null;
     //debug($params);
     if (isset($params['source'])) {
         $handle = fopen($params['source'], "rb");
         $feed = stream_get_contents($handle);
         fclose($handle);
     } else {
         echo 'A source is required.';
     }
     //debug($feed);
     $feed = new SimpleXmlElement($feed);
     if (isset($params['limit']) and $params['limit'] > 0) {
         // Not possible in SimpleXmlElement objects
     }
     //debug($feed); exit;
     if (isset($params['raw']) and $params['raw'] === true) {
         echo $feed->asXml();
     }
     if (isset($params['convert']) and $params['convert'] == 'json') {
         $feed = $this->convertToJson($feed->asXml());
     }
     //debug($feed);
     echo $feed;
 }
开发者ID:bjlbernal,项目名称:feeds,代码行数:26,代码来源:api.php


示例5: 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


示例6: 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


示例7: get

 public function get($count = -1, $rating = null, $filter = null)
 {
     if ($count == 0 || !is_numeric($count)) {
         $count = -1;
     }
     $url = sprintf(self::BACKEND_URL, $this->username) . ($filter == -1 ? '+in%3Ascraps' : '') . ($filter > 0 ? '%2F' . $filter : '');
     $this->data = $this->request($url);
     $xml = new SimpleXmlElement($this->data);
     $ns = $xml->getNamespaces(true);
     $items = null;
     foreach ($xml->channel->item as $item) {
         $media = $item->children($ns['media']);
         if (!(empty($this->rating) || $this->rating == 'all') && $media->rating != $this->rating) {
             continue;
         }
         if ($media->text) {
             continue;
         }
         if ($media->text) {
             continue;
         }
         if ($media->text) {
             continue;
         }
         $items .= sprintf('<li><a href="%1$s" title="%2$s - %3$s"><img src="%4$s" alt="%2$s - %3$s"/></a></li>', $item->link, $media->title, $media->copyright, $media->content->attributes()->url);
         --$count;
         if ($count > -1 && $count == 0) {
             break;
         }
     }
     return sprintf('<ul class="da-widgets gallery">%s</ul>', $items);
 }
开发者ID:aegypius,项目名称:wp-da-widgets,代码行数:32,代码来源:Gallery.php


示例8: 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


示例9: _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


示例10: Save

 public function Save()
 {
     //if installed goto dashboard
     if ($this->getSystemSetting(OpenSms::INSTALLATION_STATUS)) {
         OpenSms::redirectToAction('index', 'dashboard');
     }
     //var_dump($_POST);die();
     // CREATE
     $config = new SimpleXmlElement('<settings/>');
     $config->{OpenSms::VERSION} = $this->getSystemSetting(OpenSms::VERSION);
     $config->{OpenSms::SITE_NAME} = $this->getFormData(OpenSms::SITE_NAME);
     $config->{OpenSms::SITE_URL} = $this->getFormData(OpenSms::SITE_URL);
     $config->{OpenSms::DB_TYPE} = 'mysql';
     $config->{OpenSms::DB_HOST} = $this->getFormData(OpenSms::DB_HOST);
     $config->{OpenSms::DB_NAME} = $this->getFormData(OpenSms::DB_NAME);
     $config->{OpenSms::DB_TABLE_PREFIX} = $this->getFormData(OpenSms::DB_TABLE_PREFIX);
     $config->{OpenSms::DB_USERNAME} = $this->getFormData(OpenSms::DB_USERNAME);
     $config->{OpenSms::DB_PASSWORD} = $this->getFormData(OpenSms::DB_PASSWORD);
     $config->{OpenSms::DB_PASSWORD} = $this->getFormData(OpenSms::DB_PASSWORD);
     $config->{OpenSms::CURRENT_THEME_KEY} = $this->getFormData(OpenSms::CURRENT_THEME_KEY);
     $config->{OpenSms::OPEN_PRICE_PER_UNIT} = $this->getFormData(OpenSms::OPEN_PRICE_PER_UNIT);
     $config->{OpenSms::OPEN_UNITS_PER_SMS} = $this->getFormData(OpenSms::OPEN_UNITS_PER_SMS);
     $config->{OpenSms::INSTALLATION_STATUS} = false;
     //unlink(OpenSms::SETTINGS_FILE_PATH);
     $config->saveXML(OpenSms::SETTINGS_FILE_PATH);
     $this->setNotification('Settings saved', 'settings_save');
     OpenSms::redirectToAction('index');
 }
开发者ID:rumi55,项目名称:openbulksms,代码行数:28,代码来源:settings.php


示例11: parse

 public function parse()
 {
     $sXML = new \SimpleXmlElement($this->xml);
     $ns = $sXML->getNamespaces(true);
     foreach ((array) $sXML->channel as $k => $v) {
         if ($k == 'item') {
             continue;
         }
         if (!is_string($v) && !is_array($v)) {
             $v = (array) $v;
         }
         $this->meta[$k] = $v;
     }
     foreach ($sXML->channel->item as $item) {
         $i = (array) $item;
         foreach ($ns as $space => $val) {
             $children = $item->children($val);
             if ($children) {
                 foreach ($children as $c => $a) {
                     $i[$c] = (string) $a;
                 }
             }
         }
         $this->items[] = $i;
     }
 }
开发者ID:sketchmedia,项目名称:sketchguild,代码行数:26,代码来源:Rss.php


示例12: 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


示例13: parseXml

 /**
  * Parse the input SimpleXmlElement into an array
  *
  * @param SimpleXmlElement $node xml to parse
  * @return array
  */
 protected function parseXml($node)
 {
     $data = array();
     foreach ($node->children() as $key => $subnode) {
         if ($subnode->count()) {
             $value = $this->parseXml($subnode);
             if ($subnode->attributes()) {
                 foreach ($subnode->attributes() as $attrkey => $attr) {
                     $value['@' . $attrkey] = (string) $attr;
                 }
             }
         } else {
             $value = (string) $subnode;
         }
         if ($key === 'item') {
             if (isset($subnode['key'])) {
                 $data[(string) $subnode['key']] = $value;
             } elseif (isset($data['item'])) {
                 $tmp = $data['item'];
                 unset($data['item']);
                 $data[] = $tmp;
                 $data[] = $value;
             }
         } elseif (key_exists($key, $data)) {
             if (false === is_array($data[$key])) {
                 $data[$key] = array($data[$key]);
             }
             $data[$key][] = $value;
         } else {
             $data[$key] = $value;
         }
     }
     return $data;
 }
开发者ID:rooster,项目名称:symfony,代码行数:40,代码来源:XmlEncoder.php


示例14: getPath

 /**
  * Gets a path to a node via SPL Stack implementation
  *
  * Pass in the child node and will recurse up the XML tree to print out
  * the path in the tree to that node
  *
  * <config>
  *   <path>
  *     <to>
  *       <node>
  *         Node Value
  *       </node>
  *     </to>
  *   </path>
  * </config>
  *
  * If you pass in the "node" object, this will print out
  * config/path/to/node/
  *
  * @param SimpleXmlElement $element Child element to find path to
  *
  * @return string
  * @access public
  */
 public function getPath(SimpleXmlElement $element)
 {
     $this->_iterator->push($element->getName() . '/');
     if (!$element->getSafeParent()) {
         return $this->_iterator->pop();
     }
     return $this->getPath($element->getParent()) . $this->_iterator->pop();
 }
开发者ID:Rodrifer,项目名称:candyclub,代码行数:32,代码来源:Stack.php


示例15: getPath

 /**
  * Gets a path to a node via array implementation
  *
  * Pass in the child node and will recurse up the XML tree to print out
  * the path in the tree to that node
  *
  * <config>
  *   <path>
  *     <to>
  *       <node>
  *         Node Value
  *       </node>
  *     </to>
  *   </path>
  * </config>
  *
  * If you pass in the "node" object, this will print out
  * config/path/to/node/
  *
  * @param SimpleXmlElement $element Child element to find path to
  *
  * @return string
  * @access public
  */
 public function getPath(SimpleXmlElement $element)
 {
     $this->_iterator[] = $element->getName() . '/';
     if (!$element->getSafeParent()) {
         return array_pop($this->_iterator);
     }
     return $this->getPath($element->getParent()) . array_pop($this->_iterator);
 }
开发者ID:bevello,项目名称:bevello,代码行数:32,代码来源:Array.php


示例16: readAttributesArray

 /**
  * return an xml elements attributes in as array
  * @param \SimpleXmlElement $element
  * @return array
  */
 protected function readAttributesArray(\SimpleXmlElement $element)
 {
     $attributes = [];
     foreach ($element->attributes() as $attrName => $attr) {
         $attributes[$attrName] = (string) $attr;
     }
     return $attributes;
 }
开发者ID:dbrkls,项目名称:edifact,代码行数:13,代码来源:Analyser.php


示例17: 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


示例18: getNodeTitle

/**
 * @param SimpleXmlElement $node
 * @return string
 */
function getNodeTitle($node)
{
    if ($node->children()) {
        $nodeName = $node->children()[0]->getName();
        $subNodeName = getNodeTitle($node->children()[0]);
        return $nodeName . ($subNodeName ? ' > ' . $subNodeName : '');
    }
    return '';
}
开发者ID:yu1136,项目名称:api-examples,代码行数:13,代码来源:generate_docs.php


示例19: 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


示例20: test

/** @Assertions(2) */
function test()
{
    $x = new SimpleXmlElement();
    $a = $x->asXml();
    $b = $x->asXml(__FILE__);
    /** @type string|false */
    $a;
    /** @type boolean */
    $b;
}
开发者ID:walkeralencar,项目名称:ci-php-analyzer,代码行数:11,代码来源:method_interpreter_integration.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP SinglePage类代码示例发布时间:2022-05-23
下一篇:
PHP SimpleXMLObject类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap