當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SimpleXMLElement::children方法代碼示例

本文整理匯總了PHP中SimpleXMLElement::children方法的典型用法代碼示例。如果您正苦於以下問題:PHP SimpleXMLElement::children方法的具體用法?PHP SimpleXMLElement::children怎麽用?PHP SimpleXMLElement::children使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SimpleXMLElement的用法示例。


在下文中一共展示了SimpleXMLElement::children方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _xmlToArray

	/**
	 * Converts a SimpleXMLElement object into an array recurrsively.
	 *
	 * @param \SimpleXMLElement $xmlObject the object to convert
	 * @return array the converted object
	 */
	protected function _xmlToArray($xmlObject) {
		// Setup
		$result = array();

		if(count($xmlObject->children())) {
			foreach($xmlObject->children() as $key => $value) {
				if($value->children()) {
					$value = $this->_xmlToArray($value);
				}
				else {
					$value = (string) $value;
				}

				if(array_key_exists($key, $result)) {
					if(!is_array($result[$key]) || !array_key_exists(0, $result[$key])) {
						$result[$key] = array($result[$key]);
					}

					$result[$key][] = $value;
				}
				else {
					$result[$key] = $value;
				}
			}
		}
		elseif(!isset($xmlObject['extends'])) {
			$result = (string) $xmlObject;
		}
		
		return $result;
	}
開發者ID:RogWilco,項目名稱:Bedrock-Framework,代碼行數:37,代碼來源:Xml.php

示例2: parse

 public static function parse($content)
 {
     $arr = array();
     $xml = new \SimpleXMLElement($content);
     $sml = $xml->children(XMLNamespace::SML_NAMESPACE);
     if ($sml != null) {
         $arr['uuid'] = $sml->identification->IdentifierList->identifier->Term->value;
         $gml = $xml->children(XMLNamespace::GML_NAMESPACE);
         $timePeriod = $sml->validTime->children(XMLNamespace::GML_NAMESPACE)->TimePeriod;
         $arr['startDate'] = SensorMLParser::parseSmlDate($timePeriod->beginPosition, true);
         $arr['endDate'] = SensorMLParser::parseSmlDate($timePeriod->endPosition, false);
         $arr['name'] = trim($gml->name);
         $arr['desc'] = trim($gml->description);
         $smlComponents = $sml->components;
         if ($smlComponents != null) {
             $comps = $smlComponents->ComponentList;
             $arr['components'] = array();
             foreach ($comps->component as $component) {
                 $childRef = $component->attributes(XMLNamespace::XLINK_NAMESPACE)->href;
                 $arr['components'][] = array('name' => trim($component->attributes()->name), 'ref' => $childRef, 'uuid' => basename($childRef, ".xml"));
             }
         }
     }
     return $arr;
 }
開發者ID:ifremer,項目名稱:snanny-owncloudapi,代碼行數:25,代碼來源:sensormlparser.php

示例3: read

 /**
  *
  * @param SimpleXMLElement $xmlElement
  */
 public function read(SimpleXMLElement $xmlElement)
 {
     if ($xmlElement->children()) {
         $this->read($xmlElement->children());
     }
     $this->xmlArray[] = $xmlElement;
 }
開發者ID:laiello,項目名稱:samusframework,代碼行數:11,代碼來源:LerXml.class.php

示例4: proceed

 /**
  * Proceeds the import.
  *
  * @throws Recipe_Exception_Generic
  * @return Recipe_Language_XML_Importer
  */
 public function proceed()
 {
     if (is_null($this->xml)) {
         throw new Recipe_Exception_Generic("No XML data set.");
     }
     $defaultLang = false;
     /* @var XMLObj $lang */
     foreach ($this->xml->children() as $lang) {
         if ($lang->getAttribute("action") == "setDefault") {
             $defaultLang = $lang->getName();
         }
         $createData = array("langcode" => $lang->getName(), "title" => $lang->getAttribute("title"));
         $this->getFromLangCode($lang->getName(), $createData);
         /* @var XMLObj $group */
         foreach ($lang->getChildren() as $group) {
             $this->getFromGroupName($group->getName());
             $this->importData = array();
             /* @var XMLObj $phrase */
             foreach ($group->getChildren() as $phrase) {
                 $this->importData[$phrase->getName()] = $phrase->getString();
             }
             $this->import();
         }
     }
     if ($defaultLang) {
         $this->setDefaultLanguage($defaultLang);
     }
     return $this;
 }
開發者ID:enriquesomolinos,項目名稱:Bengine,代碼行數:35,代碼來源:Importer.php

示例5: parseAndGetValues

 public function parseAndGetValues()
 {
     $count = $this->xml->children()->count();
     if ($count > 0) {
         $this->parseXMLData($this->xml);
     }
     return $this->getPreparedValues();
 }
開發者ID:Maxlander,項目名稱:shixi,代碼行數:8,代碼來源:FieldTreeImportHelper.php

示例6: parse

 public function parse()
 {
     $this->simpleXml = new \SimpleXMLElement(file_get_contents($this->file));
     $content = $this->simpleXml->children();
     foreach ($content->character as $character) {
         $this->parseCharacter($character);
     }
     return $this->dictionary;
 }
開發者ID:albertofem,項目名稱:kanjidic2-lib,代碼行數:9,代碼來源:Parser.php

示例7: getChildren

 /**
  * @return ElggXMLElement[] Child elements
  */
 public function getChildren()
 {
     $children = $this->_element->children();
     $result = array();
     foreach ($children as $val) {
         $result[] = new ElggXMLElement($val);
     }
     return $result;
 }
開發者ID:duanhv,項目名稱:mdg-social,代碼行數:12,代碼來源:ElggXMLElement.php

示例8: __construct

 /**
  * Generates table from simpleXMLElement object.
  *
  * @param $name
  * @param null $simpleXmlElement
  */
 public function __construct($name, \SimpleXMLElement $simpleXmlElement = null)
 {
     $this->setElementName($name);
     if ($simpleXmlElement) {
         $this->setColHeadings((array) $simpleXmlElement->children()->colHeading);
         foreach ($simpleXmlElement->children()->row as $row) {
             $this->addRow((array) $row->col);
         }
     }
 }
開發者ID:lukebeer,項目名稱:broadworks-ocip,代碼行數:16,代碼來源:TableType.php

示例9: getNodes

 /**
  * {@inheritdoc}
  */
 public function getNodes($name)
 {
     $nodes = [];
     foreach ($this->data->children() as $kNode => $node) {
         if ($kNode != $name) {
             continue;
         }
         $nodes[] = new XmlFileNode([$kNode], $node);
     }
     return $nodes;
 }
開發者ID:itephp,項目名稱:framework,代碼行數:14,代碼來源:XmlFileReader.php

示例10: hasChildren

 /**
  * Check whether element has children
  *
  * @param \SimpleXMLElement $element
  * @return bool
  */
 public function hasChildren(\SimpleXMLElement $element)
 {
     if (!$element->children()) {
         return false;
     }
     // simplexml bug: @attributes is in children() but invisible in foreach
     foreach ($element->children() as $child) {
         return true;
     }
     return false;
 }
開發者ID:Mohitsahu123,項目名稱:mtf,代碼行數:17,代碼來源:XmlConverter.php

示例11: doPrettyPrintXML

 private function doPrettyPrintXML(SimpleXMLElement $han, $prefix = "")
 {
     if (count($han->children()) < 1) {
         return $prefix . "&lt;" . $han->getName() . $this->doWarpAttributes($han->attributes()) . "&gt;" . $han . "&lt;/" . $han->getName() . "&gt;<br />";
     }
     $ret = $prefix . "&lt;" . $han->getName() . $this->doWarpAttributes($han->attributes()) . "&gt;<br />";
     foreach ($han->children() as $key => $child) {
         $ret .= $this->doPrettyPrintXML($child, $prefix . "    ");
     }
     $ret .= $prefix . "&lt;/" . $han->getName() . "&gt;<br />";
     return $ret;
 }
開發者ID:neelaryan,項目名稱:mutillidae,代碼行數:12,代碼來源:XMLHandler.php

示例12: __construct

 public function __construct($xmlString = '')
 {
     $this->xml = simplexml_load_string($xmlString);
     if (!empty($xmlString)) {
         foreach ($this->xml->children() as $name => $data) {
             if ($this->hasProperty($name)) {
                 $this->{$name} = trim($data);
             }
         }
     }
     parent::__construct();
 }
開發者ID:just-leo,項目名稱:cardgame-serial,代碼行數:12,代碼來源:ServiceData.php

示例13: parseValueInside

 /**
  * Parses and returns the value inside the specified XML element.
  * 
  * @param SimpleXMLElement $containerXml
  * @return mixed
  */
 public static function parseValueInside($containerXml)
 {
     $dictValue = $containerXml->children(Splunk_AtomFeed::NS_S)->dict;
     $listValue = $containerXml->children(Splunk_AtomFeed::NS_S)->list;
     if (Splunk_XmlUtil::elementExists($dictValue)) {
         return Splunk_AtomFeed::parseDict($dictValue);
     } else {
         if (Splunk_XmlUtil::elementExists($listValue)) {
             return Splunk_AtomFeed::parseList($listValue);
         } else {
             return Splunk_XmlUtil::getTextContent($containerXml);
         }
     }
 }
開發者ID:hongweipeng,項目名稱:screen,代碼行數:20,代碼來源:AtomFeed.php

示例14: SimpleXMLElement

 /**
  * Lookup the DOI from the crossref site
  */
 function _lookupdoi($doi)
 {
     // Get the API key from the config file
     $apikey = $this->config->item('easydeposit_crossrefdoilookup_apikey');
     // Check the DOI is in the correct format (strip any http prefix)
     $doi = str_replace('http://dx.doi.org/', '', $doi);
     if (strpos($doi, '10.') !== 0 || strlen($doi) < 4) {
         $this->form_validation->set_message('_lookupdoi', 'Bad DOI');
         return FALSE;
     }
     // Get the DOI, throw an error if we can't connect
     if (!($response = file_get_contents('http://www.crossref.org/openurl/?id=doi:' . $doi . '&noredirect=true&format=unixref&pid=' . $apikey))) {
         $this->form_validation->set_message('_lookupdoi', 'Error connecting to CrossRef');
         return FALSE;
     }
     // An example of a response, useful if developing or debugging offline
     //$response = '<doi_records xmlns="http://www.crossref.org/xschema/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.crossref.org/xschema/1.1 http://www.crossref.org/schema/unixref1.1.xsd http://www.crossref.org/xschema/1.0 http://www.crossref.org/schema/unixref1.0.xsd"><doi_record xmlns="http://www.crossref.org/xschema/1.0" owner="10.1108" timestamp="2009-10-10 07:01:10.0"><crossref><journal><journal_metadata language="en"><full_title>Program: electronic library and information systems</full_title><abbrev_title>Program: electronic library and information systems</abbrev_title><issn media_type="print">0033-0337</issn></journal_metadata><journal_issue><publication_date media_type="print"><year>2009</year></publication_date><journal_volume><volume>43</volume></journal_volume><issue>4</issue></journal_issue><journal_article publication_type="full_text"><titles><title>If SWORD is the answer, what is the question?: Use of the Simple Web-service Offering Repository Deposit protocol</title></titles><contributors><person_name sequence="first" contributor_role="author"><given_name>Stuart</given_name><surname>Lewis</surname></person_name><person_name sequence="additional" contributor_role="author"><given_name>Leonie</given_name><surname>Hayes</surname></person_name><person_name sequence="additional" contributor_role="author"><given_name>Vanessa</given_name><surname>Newton-Wade</surname></person_name><person_name sequence="additional" contributor_role="author"><given_name>Antony</given_name><surname>Corfield</surname></person_name><person_name sequence="additional" contributor_role="author"><given_name>Richard</given_name><surname>Davis</surname></person_name><person_name sequence="additional" contributor_role="author"><given_name>Tim</given_name><surname>Donohue</surname></person_name><person_name sequence="additional" contributor_role="author"><given_name>Scott</given_name><surname>Wilson</surname></person_name></contributors><publication_date media_type="print"><year>2009</year></publication_date><pages><first_page>407</first_page><last_page>418</last_page></pages><doi_data><doi>10.1108/00330330910998057</doi><resource>http://www.emeraldinsight.com/10.1108/00330330910998057</resource></doi_data><citation_list/></journal_article></journal></crossref></doi_record></doi_records>';
     // Parse and process the xml
     $xml = new SimpleXMLElement($response);
     $error = $xml->children()->doi_record->crossref->error;
     if (!empty($error)) {
         $this->form_validation->set_message('_lookupdoi', $error);
         return FALSE;
     }
     // Looks like we have a match, so process it
     $record = $xml->children()->doi_record->crossref->journal;
     $_SESSION['crossrefdoi-title'] = $record->journal_article->titles->title . '';
     $contributors = $record->journal_article->contributors;
     $authorcount = 0;
     foreach ($contributors->person_name as $contributor) {
         $_SESSION['crossrefdoi-author' . ++$authorcount] = $contributor->surname . ', ' . $contributor->given_name;
     }
     $_SESSION['crossrefdoi-authorcount'] = $authorcount;
     $_SESSION['crossrefdoi-year'] = $record->journal_article->publication_date->year . '';
     $_SESSION['crossrefdoi-journaltitle'] = $record->journal_metadata->full_title . '';
     $pstart = $record->journal_article->pages->first_page;
     $pend = $record->journal_article->pages->last_page;
     $pages = '';
     if (!empty($pstart)) {
         $pages = $pstart;
         if (!empty($pend)) {
             $pages .= '-' . $pend;
         }
     }
     $_SESSION['crossrefdoi-volume'] = $record->journal_issue->journal_volume->volume . '';
     $_SESSION['crossrefdoi-issue'] = $record->journal_issue->issue . '';
     return TRUE;
 }
開發者ID:stuartlewis,項目名稱:EasyDeposit,代碼行數:51,代碼來源:crossrefdoilookup.php

示例15: itCreatesAnXMLEntryForEachPlanningShortAccess

 public function itCreatesAnXMLEntryForEachPlanningShortAccess()
 {
     $exporter = new AgileDashboard_XMLExporter($this->xml_validator, $this->planning_permissions_manager);
     $exporter->export($this->xml_tree, $this->plannings);
     $this->assertEqual(1, count($this->xml_tree->children()));
     $agiledashborad = AgileDashboard_XMLExporter::NODE_AGILEDASHBOARD;
     $plannings = AgileDashboard_XMLExporter::NODE_PLANNINGS;
     foreach ($this->xml_tree->{$agiledashborad}->children() as $plannings_node) {
         $this->assertEqual(2, count($plannings_node->children()));
         $this->assertEqual($plannings_node->getName(), $plannings);
     }
     foreach ($this->xml_tree->{$agiledashborad}->{$plannings}->children() as $planning) {
         $this->assertEqual($planning->getName(), AgileDashboard_XMLExporter::NODE_PLANNING);
         $this->assertEqual(1, count($planning->children()));
     }
 }
開發者ID:pombredanne,項目名稱:tuleap,代碼行數:16,代碼來源:XMLExporterTest.php


注:本文中的SimpleXMLElement::children方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。