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


PHP SimpleXMLElement类代码示例

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


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

示例1: encode

 public function encode(\Esendex\Model\DispatchMessage $message)
 {
     if (strlen($message->originator()) < 1) {
         throw new ArgumentException("Originator is invalid");
     }
     if (strlen($message->recipient()) < 1) {
         throw new ArgumentException("Recipient is invalid");
     }
     if ($message->validityPeriod() > 72) {
         throw new ArgumentException("Validity too long, must be less or equal to than 72");
     }
     $doc = new \SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><messages />", 0, false, Api::NS);
     $doc->accountreference = $this->reference;
     $child = $doc->addChild("message");
     $child->from = $message->originator();
     $child->to = $message->recipient();
     $child->body = $message->body();
     $child->type = $message->type();
     if ($message->validityPeriod() > 0) {
         $child->validity = $message->validityPeriod();
     }
     if ($message->language() != null) {
         $child->lang = $message->language();
     }
     return $doc->asXML();
 }
开发者ID:leqg,项目名称:leqg,代码行数:26,代码来源:DispatchXmlParser.php

示例2: __construct

 public function __construct($lg = 'fr')
 {
     parent::__construct($lg);
     $this->lg = URL . 't/' . $lg . '/';
     $base = $this->lg;
     $this->xmlOut = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
     $this->xmlOut .= "<url><loc>{$base}</loc><priority>1.00</priority><changefreq>daily</changefreq></url>";
     $this->Gen();
     $this->xmlOut .= '</urlset>';
     $fileSitemap = BASE . 'sitemap.xml';
     $newXml = new SimpleXMLElement($this->xmlOut);
     $newXml->asXML($fileSitemap);
     $aL = $this->allLanguages;
     foreach ($aL as $k => $v) {
         parent::__construct($k);
         $this->lg = URL . 't/' . $k . '/';
         $base = $this->lg;
         $this->xmlOut = '';
         $this->xmlOut = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
         $this->xmlOut .= "<url><loc>{$base}</loc><priority>1.00</priority><changefreq>daily</changefreq></url>";
         $this->Gen();
         $this->xmlOut .= '</urlset>';
         $fileSitemap = BASE . 't/' . $k . '/sitemap.xml';
         $newXml = new SimpleXMLElement($this->xmlOut);
         $newXml->asXML($fileSitemap);
     }
 }
开发者ID:neoartdoo,项目名称:CMS,代码行数:27,代码来源:GenSitemapXml.php

示例3: export

 public function export(SimpleXMLElement $blockNode)
 {
     $stack = Stack::getByID($this->stID);
     if (is_object($stack)) {
         $blockNode->addChild('stack', '<![CDATA[' . $stack->getCollectionName() . ']]>');
     }
 }
开发者ID:ricardomccerqueira,项目名称:rcerqueira.portfolio,代码行数:7,代码来源:core_stack_display.php

示例4: toArray

 /**
  * Convert an XML document to a multi dimensional array
  * Pass in an XML document (or SimpleXMLElement object) and this recrusively loops through and builds a representative array
  *
  * @param string $xml - XML document - can optionally be a SimpleXMLElement object
  * @return array ARRAY
  */
 public static function toArray($xml)
 {
     if (is_string($xml)) {
         $xml = new SimpleXMLElement($xml);
     }
     $children = $xml->children();
     if (!$children) {
         return (string) $xml;
     }
     $arr = array();
     foreach ($children as $key => $node) {
         $node = ArrayToXML::toArray($node);
         // support for 'anon' non-associative arrays
         if ($key == 'anon') {
             $key = count($arr);
         }
         // if the node is already set, put it into an array
         if (isset($arr[$key])) {
             if (!is_array($arr[$key]) || !isset($arr[$key][0])) {
                 $arr[$key] = array($arr[$key]);
             }
             $arr[$key][] = $node;
         } else {
             $arr[$key] = $node;
         }
     }
     return $arr;
 }
开发者ID:carriercomm,项目名称:opengateway,代码行数:35,代码来源:arraytoxml.php

示例5: displayBookings

function displayBookings()
{
    $host;
    $user;
    $pswd;
    $dbnm;
    $connection = mysqli_connect($host, $user, $pswd, $dbnm) or die('Failed to connect.');
    $searchQuery = "SELECT * FROM bookings where status = 'unassigned'";
    $result = mysqli_query($connection, $searchQuery);
    $xml = new SimpleXMLElement('<xml/>');
    if (mysqli_num_rows($result) > 0) {
        while ($result_array = mysqli_fetch_array($result)) {
            $data = $xml->addChild('search');
            $data->addChild('bookingNumber', $result_array['bookingNumber']);
            $data->addChild('customerName', $result_array['customerName']);
            $data->addChild('pickupAddress', $result_array['pickupAddress']);
            $data->addChild('suburb', $result_array['suburb']);
            $data->addChild('destination', $result_array['destination']);
            $data->addChild('phoneNumber', $result_array['contactPhone']);
            $data->addChild('pickUpDate', $result_array['pickUpDate']);
            $data->addChild('pickUpTime', $result_array['pickUpTime']);
            $data->addChild('bookingDate', $result_array['bookingDate']);
            $data->addChild('bookingTime', $result_array['bookingTime']);
        }
    }
    echo $xml->asXML();
}
开发者ID:romangn,项目名称:Taxi-booking-system,代码行数:27,代码来源:showBookings.php

示例6: __construct

 /**
  * Parses the affix configuration.
  *
  * @param \SimpleXMLElement $date
  * @param array $additional Array with key form and value text or numeric
  */
 public function __construct(\SimpleXMLElement $date, array $additional)
 {
     $this->name = '';
     $this->delimiter = '–';
     $this->formatting = new Formatting($date);
     $this->textCase = new TextCase($date);
     $this->affix = new Affix($date);
     foreach ($date->attributes() as $name => $value) {
         switch ($name) {
             case 'name':
                 $this->name = (string) $value;
                 switch ($this->name) {
                     case 'day':
                         $this->render = Factory::day($additional['form'], $date);
                         break;
                     case 'month':
                         $this->render = Factory::month($additional['form'], $date);
                         break;
                     case 'year':
                         $this->render = Factory::year($additional['form'], $date);
                         break;
                 }
                 break;
             case 'range-delimiter':
                 $this->delimiter = (string) $value;
                 break;
         }
     }
 }
开发者ID:geissler,项目名称:csl,代码行数:35,代码来源:DatePart.php

示例7: processSvn2RssRequest

 /**
  * Starts the processing of the current rss-request.
  * Acts like some kind of a main-method, so manages the further control-flow.
  */
 public function processSvn2RssRequest($strFeedParam = "")
 {
     try {
         //start by loading the config-file
         $objConfig = new ConfigReader($strFeedParam);
         //create the svn-reader and pass control
         $objSvnReader = new SvnReader($objConfig);
         $strSvnLog = $objSvnReader->getSvnLogContent();
         //create rss-nodes out of the logfile
         $objRssConverter = new Log2RssConverter($objConfig);
         $objRssRootNode = $objRssConverter->generateRssNodesFromLogContent($strSvnLog);
         $this->strOutput = $objRssRootNode->asXML();
     } catch (Svn2RssException $objException) {
         //Wrap error-message as a rss-feed element, too
         $objFeedRootNode = new SimpleXMLElement("<rss version=\"2.0\"></rss>");
         $objChannel = $objFeedRootNode->addChild("channel");
         $objChannel->addChild("title", "Error");
         $objChannel->addChild("description", "Error while loading feed");
         $objChannel->addChild("link", "n.a.");
         $objChannel->addChild("pubDate", strftime("%a, %d %b %Y %H:%M:%S GMT", time()));
         $objRssItemNode = $objChannel->addChild("item");
         $objRssItemNode->addChild("title", "Something bad happened: \n" . $objException->getMessage() . "");
         $objRssItemNode->addChild("description", "Something bad happened: \n" . $objException->getMessage() . "");
         $objRssItemNode->addChild("pubDate", strftime("%a, %d %b %Y %H:%M:%S GMT", time()));
         $this->strOutput = $objFeedRootNode->asXML();
     }
 }
开发者ID:rcappuccio,项目名称:gitsvn,代码行数:31,代码来源:Svn2Rss.php

示例8: load

 public function load($inputFile)
 {
     $objects = array();
     if (!file_exists($inputFile)) {
         KalturaLog::err("input file " . $inputFile . " not found");
         exit(1);
     }
     $inputXml = file_get_contents($inputFile);
     $xml = new SimpleXMLElement($inputXml);
     foreach ($xml->children() as $searchableObject) {
         $objectAttribtues = $searchableObject->attributes();
         $objName = $objectAttribtues["name"];
         $this->parseObject("{$objName}", $objectAttribtues);
         $this->searchableIndices["{$objName}"] = array();
         foreach ($searchableObject->children() as $type => $searchableField) {
             switch ($type) {
                 case "field":
                     $this->parseField("{$objName}", $searchableField);
                     break;
                 case "index":
                     $this->parseIndex("{$objName}", $searchableField);
                     break;
             }
         }
         $objects[] = "{$objName}";
     }
     return $objects;
 }
开发者ID:visomar,项目名称:server,代码行数:28,代码来源:IndexObjectsGenerator.php

示例9: getImportantActs

function getImportantActs($xml_url, $xsl_filename, $n_nodes)
{
    try {
        // read the xml from url
        $xmldoc = new DomDocument();
        $xmldoc->load($xml_url);
        // read xslt file
        $xsldoc = new DomDocument();
        $xsldoc->load($xsl_filename);
        $xsl = new XSLTProcessor();
        $xsl->importStyleSheet($xsldoc);
        // trasforma XML secondo l'XSLT ed estrae il contenuto del div
        $transformed_xml = new SimpleXMLElement($xsl->transformToXML($xmldoc));
        $nodes = $transformed_xml->children();
        // write values to screen
        $cnt = 0;
        foreach ($nodes as $node) {
            $cnt++;
            $atto = OppAttoPeer::retrieveByPK($node['atto_id']);
            printf("\t%d. %s => %f\n", $cnt, $atto->getTitoloCompleto(), $node['totale']);
            if ($cnt >= $n_nodes) {
                break;
            }
        }
    } catch (Exception $e) {
        printf("Errore durante la scrittura del file: %s\n", $e->getMessage());
    }
}
开发者ID:valerio-bozzolan,项目名称:openparlamento,代码行数:28,代码来源:anno0Tasks.php

示例10: xmlpp

 /** Prettifies an XML string into a human-readable and indented work of art
  *  @param string $xml The XML as a string
  *  @param boolean $html_output True if the output should be escaped (for use in HTML)
  */
 public static function xmlpp($xml, $html_output = false)
 {
     $xml_obj = new SimpleXMLElement($xml);
     $level = 4;
     $indent = 0;
     // current indentation level
     $pretty = array();
     // get an array containing each XML element
     $xml = explode("\n", preg_replace('/>\\s*</', ">\n<", $xml_obj->asXML()));
     // shift off opening XML tag if present
     if (count($xml) && preg_match('/^<\\?\\s*xml/', $xml[0])) {
         $pretty[] = array_shift($xml);
     }
     foreach ($xml as $el) {
         if (preg_match('/^<([\\w])+[^>\\/]*>$/U', $el)) {
             // opening tag, increase indent
             $pretty[] = str_repeat(' ', $indent) . $el;
             $indent += $level;
         } else {
             if (preg_match('/^<\\/.+>$/', $el)) {
                 $indent -= $level;
                 // closing tag, decrease indent
             }
             if ($indent < 0) {
                 $indent += $level;
             }
             $pretty[] = str_repeat(' ', $indent) . $el;
         }
     }
     $xml = implode("\n", $pretty);
     return $html_output ? htmlentities($xml) : $xml;
 }
开发者ID:jmhobbs,项目名称:Twillip,代码行数:36,代码来源:twillip.php

示例11: _assocToXml

 /**
  * Function, that actually recursively transforms array to xml
  *
  * @param array $array
  * @param string $rootName
  * @param \SimpleXMLElement $xml
  * @return \SimpleXMLElement
  * @throws Exception
  */
 private function _assocToXml(array $array, $rootName, \SimpleXMLElement $xml)
 {
     $hasNumericKey = false;
     $hasStringKey = false;
     foreach ($array as $key => $value) {
         if (!is_array($value)) {
             if (is_string($key)) {
                 if ($key === $rootName) {
                     throw new Exception('Associative key must not be the same as its parent associative key.');
                 }
                 $hasStringKey = true;
                 $xml->addChild($key, $value);
             } elseif (is_int($key)) {
                 $hasNumericKey = true;
                 $xml->addChild($key, $value);
             }
         } else {
             $xml->addChild($key);
             self::_assocToXml($value, $key, $xml->{$key});
         }
     }
     if ($hasNumericKey && $hasStringKey) {
         throw new Exception('Associative and numeric keys must not be mixed at one level.');
     }
     return $xml;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:35,代码来源:ConvertArray.php

示例12: parseMaps

 private function parseMaps(\SimpleXMLElement $xml)
 {
     $maps = array();
     if (array_key_exists('maps', $this->mapping)) {
         foreach ($this->mapping['maps'] as $key => $item) {
             /* --- XML NS --- */
             if ('MobileRelatedApps' == $this->name) {
                 /** @var $element \SimpleXMLElement */
                 $element = $xml->{'RelatedApps'};
                 $ns = $xml->getNamespaces(true);
                 $map = array();
                 foreach ($element->children($ns['d2p1']) as $element) {
                     $map[(string) $element->{$item['xml']['key']}] = (string) $element->{$item['xml']['value']};
                 }
                 $maps[$key] = $map;
                 continue;
             }
             /* --- XML NS --- */
             $map = array();
             $parts = explode('.', $item['xml']['field']);
             $items = array();
             if (2 == count($parts)) {
                 $items = $xml->{$parts[0]}->{$parts[1]};
             }
             foreach ($items as $element) {
                 $map[(string) $element->{$item['xml']['key']}] = (string) $element->{$item['xml']['value']};
             }
             $maps[$key] = $map;
         }
     }
     return $maps;
 }
开发者ID:gerdlaser,项目名称:SimilarWebApi,代码行数:32,代码来源:XmlParser.php

示例13: sxml_show_info

/**
 * @param SimpleXMLElement $element
 */
function sxml_show_info(SimpleXMLElement $element)
{
    $isSingleElement = $element[0] == $element;
    $isListOfElements = $element[0] != $element and $element->attributes() !== NULL;
    printf("  Is single-element?   - %s\n", $isSingleElement ? 'Yes' : 'No');
    printf("  Is list-of-elements? - %s\n", $isListOfElements ? 'Yes' : 'No');
}
开发者ID:shambhukumar,项目名称:code,代码行数:10,代码来源:simple.php

示例14: buildXML

 /**
  * Build the XML for an issue
  * @param  array             $params for the new/updated issue data
  * @return \SimpleXMLElement
  */
 private function buildXML(array $params = array())
 {
     $xml = new \SimpleXMLElement('<?xml version="1.0"?><issue></issue>');
     foreach ($params as $k => $v) {
         if ('custom_fields' === $k && is_array($v)) {
             $custom_fields_item = $xml->addChild('custom_fields', '');
             $custom_fields_item->addAttribute('type', 'array');
             foreach ($v as $field) {
                 $item = $custom_fields_item->addChild('custom_field', '');
                 $item->addAttribute('id', (int) $field['id']);
                 $item->addChild('value', $field['value']);
             }
         } elseif ('watcher_user_ids' === $k && is_array($v)) {
             $watcher_user_ids = $xml->addChild('watcher_user_ids', '');
             $watcher_user_ids->addAttribute('type', 'array');
             foreach ($v as $watcher) {
                 $watcher_user_ids->addChild('watcher_user_id', (int) $watcher);
             }
         } elseif ('uploads' === $k && is_array($v)) {
             $uploads_item = $xml->addChild('uploads', '');
             $uploads_item->addAttribute('type', 'array');
             foreach ($v as $upload) {
                 $upload_item = $uploads_item->addChild('upload', '');
                 foreach ($upload as $upload_k => $upload_v) {
                     $upload_item->addChild($upload_k, $upload_v);
                 }
             }
         } else {
             $xml->addChild($k, $v);
         }
     }
     return $xml;
 }
开发者ID:iseth,项目名称:php-www,代码行数:38,代码来源:Issue.php

示例15: 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();
 }
开发者ID:hukumonline,项目名称:zfurl,代码行数:31,代码来源:ApiController.php


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