当前位置: 首页>>代码示例>>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;未经允许,请勿转载。