本文整理汇总了PHP中SimpleXMLIterator类的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLIterator类的具体用法?PHP SimpleXMLIterator怎么用?PHP SimpleXMLIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleXMLIterator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: parseFile
/**
* Parse csv file for getting its metadata
* @param \SimpleXMLIterator $data data
* @return multitype:Ambigous <>
*/
public function parseFile($data)
{
try {
$temp = (array) $data;
$fileName = $temp['fileName'];
$dataType = $temp['dataType'];
$duplicateHandle = $data['duplicateHandle'];
$fileStorageId = (string) $temp['fileStorageId'];
$fullPath = (string) $temp['fullPath'];
// count file
$fp = file($fullPath);
$count = count($fp) - 1;
// Get headers
$header = array();
if (($handle = fopen($fullPath, "r")) !== false) {
// no row length limit plus csv escape with '
while (($csvRow = fgetcsv($handle, 0, ",", "'")) !== false) {
for ($columnNo = 0, $columnCount = count($csvRow); $columnNo < $columnCount; $columnNo++) {
$header[] = $csvRow[$columnNo];
$data->headers->addChild($columnNo, (string) $csvRow[$columnNo]);
}
break;
}
fclose($handle);
}
$data->records = $count;
$file = $data->addChild('file');
$file->addChild('fileName', (string) $temp['fileName']);
$file->addChild('fileStorageId', $fileStorageId);
unset($data->fileStorageId);
unset($data->fileName);
unset($data->fullPath);
$response = $this->edit($data);
// Make response
$response['fileName'] = $fileName;
$response['headers'] = $header;
return $response;
} catch (\Exception $e) {
echo $e->getMessage();
}
}
开发者ID:EngrHaiderAli,项目名称:movein-servie,代码行数:46,代码来源:CsvImport.php
示例2: edit
/**
* save and edit system template document
* @param unknown $data data
* @return Ambigous <multitype:, multitype:Ambigous <boolean, \Base\Model\Service\Ambigous, multitype:, string, unknown, object> NULL >
*/
public function edit($data)
{
if (isset($data->id) && !empty($data->id) && isset($data->generatedOn)) {
unset($data->recipient);
}
$result = parent::edit($data);
$response = new \SimpleXMLIterator('<?xml version="1.0" encoding="UTF-8"?><template/>');
$response->addChild('id', (string) $result['id']);
$response->addChild('fields', 'recipient');
$recipients = $this->getOne($response);
$result['recipients'] = $recipients['fields'];
return $result;
}
开发者ID:EngrHaiderAli,项目名称:movein-servie,代码行数:18,代码来源:ActivitySystemTemplate.php
示例3: get_elements_from_supplied_file
function get_elements_from_supplied_file($file)
{
$found_elements = array();
if ($xml = file_get_contents($file)) {
//print_r($xml);
//SimpleXMLIterator just runs over the xml and returns the elements found in this file. I think this is just top level
//which is what I want.
//echo $xml;
/* Some safety against XML Injection attack
* see: http://phpsecurity.readthedocs.org/en/latest/Injection-Attacks.html
*
* Attempt a quickie detection of DOCTYPE - discard if it is present (cos it shouldn't be!)
*/
$collapsedXML = preg_replace("/[[:space:]]/", '', $xml);
//echo $collapsedXML;
if (preg_match("/<!DOCTYPE/i", $collapsedXML)) {
//throw new InvalidArgumentException(
// 'Invalid XML: Detected use of illegal DOCTYPE'
// );
//echo "fail";
return FALSE;
}
$loadEntities = libxml_disable_entity_loader(true);
$dom = new DOMDocument();
$dom->loadXML($xml);
foreach ($dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new Exception\ValueException('Invalid XML: Detected use of illegal DOCTYPE');
libxml_disable_entity_loader($loadEntities);
return FALSE;
}
}
libxml_disable_entity_loader($loadEntities);
//Iterate over elements now
if (simplexml_import_dom($dom)) {
$xmlIterator = new SimpleXMLIterator($xml);
for ($xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next()) {
foreach ($xmlIterator->getChildren() as $name => $data) {
//echo "The $name is '$data' from the class " . get_class($data) . "\n";
$found_elements[] = $name;
}
}
} else {
return FALSE;
}
}
return $found_elements;
}
开发者ID:rolfkleef,项目名称:IATI-Public-Validator,代码行数:48,代码来源:get_elements_from_supplied_file.php
示例4: _XMLNodeToArray
/**
* Recursively convert \SimpleXMLIterator to array
*
* @param \SimpleXMLIterator $XMLNode
*
* @return array
*/
private static function _XMLNodeToArray($XMLNode)
{
$result = array();
$attributes = $XMLNode->attributes();
foreach ($attributes as $k => $v) {
$val = (string) $v;
if ($val == "True" || $val == "False") {
$val = (bool) $val;
}
$result[$k] = $val;
}
$children = $XMLNode->children();
foreach ($children as $chK => $chNode) {
$result['Items'][] = self::_XMLNodeToArray($chNode);
}
return $result;
}
开发者ID:bfday,项目名称:yii2-payture-module,代码行数:24,代码来源:Payture.php
示例5: xmlToArray
private function xmlToArray(\SimpleXMLIterator $sxi)
{
$a = array();
for ($sxi->rewind(); $sxi->valid(); $sxi->next()) {
$t = array();
$current = $sxi->current();
$attributes = $current->attributes();
$name = isset($attributes->_key) ? strval($attributes->_key) : $sxi->key();
// save attributes
foreach ($attributes as $att_key => $att_value) {
if ($att_key !== '_key') {
$t[$att_key] = strval($att_value);
}
}
// we parse nodes
if ($sxi->hasChildren()) {
// children
$t = array_merge($t, $this->xmlToArray($current));
} else {
// it's a leaf
if (empty($t)) {
$t = strval($current);
// strval will call _toString()
} else {
$t['_value'] = strval($current);
// strval will call _toString()
}
}
$a[$name] = $t;
}
return $a;
}
开发者ID:romaricdrigon,项目名称:metayaml,代码行数:32,代码来源:XmlLoader.php
示例6: getFormUploadFields
/**
* get files to be uploaded
* @param object \SimpleXMLIterator $data data
* @return array
*/
public function getFormUploadFields($data)
{
$data = new \SimpleXMLIterator($data->asXML());
if (isset($data->values->values->formId)) {
$object = new \stdClass();
$object->id = $data->values->values->formId;
$object->fields = array('xmlDefinition');
$res = $this->getOne($object);
$formXml = file_get_contents('/var/www/htdocs/uploads/' . $res['fields']['xmlDefinition']);
$formXml = new \SimpleXMLIterator($formXml);
$uploadsFields = $formXml->xpath('//input[@type="file"]');
foreach ($uploadsFields as $field) {
$controlName = (string) $field['name'];
$control = $data->xpath('//' . $controlName);
$fieldAnswers[] = array('fieldName' => $controlName, 'value' => (string) $control[0]);
}
return array('fields' => $fieldAnswers);
} else {
return false;
}
}
开发者ID:EngrHaiderAli,项目名称:movein-servie,代码行数:26,代码来源:FormConfig.php
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$fileInfo = new \SplFileInfo($this->getContainer()->getParameter('kernel.root_dir') . '/../web/sitemap.xml');
if ($fileInfo->isFile() && $fileInfo->isReadable()) {
$output->write('Reading sitemap.xml...');
$file = $fileInfo->openFile();
$xml = '';
while (!$file->eof()) {
$xml .= $file->fgets();
}
$output->writeln(' done.');
$output->write('Updating sitemap.xml...');
$sitemap = new \SimpleXMLIterator($xml);
$sitemap->rewind();
$lastmodDate = new \DateTime();
$lastmodDate->sub(new \DateInterval('P1D'));
$lastmodDateFormatted = $lastmodDate->format('Y-m-d');
while ($sitemap->valid()) {
$sitemap->current()->lastmod = $lastmodDateFormatted;
$sitemap->next();
}
$file = $file->openFile('w');
$file->fwrite($sitemap->asXML());
$output->writeln(' done.');
} else {
$output->writeln('Error: Cannot open file web/sitemap.xml');
}
}
开发者ID:Quiss,项目名称:Evrika,代码行数:28,代码来源:UpdateSitemapCommand.php
示例8: __construct
/**
* Create the ResultSet
*
* @param object $result
* @return void
*/
public function __construct($result)
{
$xmlIterator = new \SimpleXMLIterator($result);
for ($xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next()) {
$temp = new \stdClass();
foreach ($xmlIterator->getChildren()->attributes() as $name => $value) {
switch ($name) {
case 'orderId':
case 'brokerTicketId':
case 'quantity':
case 'purchaseOrderId':
$temp->{$name} = (int) $value;
break;
case 'cost':
$temp->{$name} = (double) $value;
break;
case 'electronicDelivery':
$temp->{$name} = (bool) $value;
break;
default:
$temp->{$name} = (string) $value;
}
}
$this->_results[] = $temp;
}
unset($xmlIterator, $temp, $name, $value);
}
开发者ID:teamonetickets,项目名称:razorgator-php,代码行数:33,代码来源:AbstractResultSet.php
示例9: unserialize
/**
* unserialize()
*
* Create a structure in the object $profile from the structure specficied
* in the xml string provided
*
* @param string xml data
* @param Zend_Tool_Project_Profile The profile to use as the top node
* @return Zend_Tool_Project_Profile
*/
public function unserialize($data, Zend_Tool_Project_Profile $profile)
{
if ($data == null) {
throw new Exception('contents not available to unserialize.');
}
$this->_profile = $profile;
$xmlDataIterator = new SimpleXMLIterator($data);
if ($xmlDataIterator->getName() != 'extensionProfile') {
throw new Exception('Extension profile must start with a extensionProfile node');
}
if (isset($xmlDataIterator['type'])) {
$this->_profile->setAttribute('type', (string) $xmlDataIterator['type']);
}
if (isset($xmlDataIterator['version'])) {
$this->_profile->setAttribute('version', (string) $xmlDataIterator['version']);
}
// start un-serialization of the xml doc
$this->_unserializeRecurser($xmlDataIterator);
// contexts should be initialized after the unwinding of the profile structure
$this->_lazyLoadContexts();
return $this->_profile;
}
开发者ID:CEMD-CN,项目名称:MageTool,代码行数:32,代码来源:Xml.php
示例10: SimpleXMLIterator
<pre>
<?php
$xml = <<<XML
<books>
<book>
<title>PHP Basics</title>
<author>Jim Smith</author>
</book>
<book>XML basics</book>
</books>
XML;
$xmlIterator = new SimpleXMLIterator($xml);
//books
for ($xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next()) {
foreach ($xmlIterator->getChildren() as $name => $data) {
echo "The {$name} is '{$data}' from the class " . get_class($data) . "\n";
}
echo $xmlIterator->getName() . "\n";
//2 times of books will be print out
}
?>
</pre>
开发者ID:pixlr,项目名称:zce-1,代码行数:22,代码来源:getChildren.php
示例11: unlink
if (!$res) {
unlink(COOKIE_FILE);
die("Cannot log in to BGZ!" . PHP_EOL);
}
if (!$quiet) {
printf("Done." . PHP_EOL . "Getting cash import file list ... ");
}
$files = get_files();
if (!$files) {
unlink(COOKIE_FILE);
die("Cannot get file list!" . PHP_EOL);
}
if (!$quiet) {
printf("Done." . PHP_EOL);
}
$xml = new SimpleXMLIterator($files);
$xml->rewind();
while ($xml->valid()) {
if ($xml->key() == "rows") {
$rows = $xml->getChildren();
$rows->rewind();
while ($rows->valid()) {
if ($rows->key() == "row") {
$fileid = $filename = NULL;
$props = $rows->getChildren();
$props->rewind();
while ($props->valid()) {
switch ($props->key()) {
case "id":
$fileid = strval($props->current());
break;
开发者ID:Akheon23,项目名称:lms,代码行数:31,代码来源:lms-cashimport-bgz.php
示例12: parseDependencyType
protected function parseDependencyType(\SimpleXMLIterator $iterator, DependencyCollection $dependencies, $required = true)
{
$iterator->rewind();
while ($iterator->valid()) {
$elt = $iterator->current();
$name = $elt->getName();
$iterator->next();
if ($name === 'php') {
$dependencies->import($this->parsePhpCondition($elt));
} elseif ($name === 'pearinstaller') {
// Let's just ignore this for now!
} else {
// TODO do not ignore recommended, nodefault and uri, providesextension
$identifier = 'pear2://' . (string) $elt->channel . '/' . (string) $elt->name;
$dependencies[] = new Dependency($identifier, isset($elt->min) ? (string) $elt->min : null, isset($elt->max) ? (string) $elt->max : null, isset($elt->conflicts) ? Dependency::CONFLICT : ($required ? Dependency::REQUIRED : Dependency::OPTIONAL));
foreach ($elt->exclude as $exclude) {
$dependencies[] = new Dependency($identifier, (string) $exclude, (string) $exclude, Dependency::CONFLICT);
}
}
}
}
开发者ID:rosstuck,项目名称:Pok,代码行数:21,代码来源:Loader.php
示例13: SimpleXMLIterator
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2015/12/1
* Time: 11:29
*/
$it = new SimpleXMLIterator(file_get_contents('test.xml'));
foreach ($it as $key => $node) {
echo $key . "<br/>";
if ($it->hasChildren()) {
foreach ($it->getChildren() as $element => $value) {
echo "\t" . $element . " : " . $value . "<br/>";
}
}
}
开发者ID:quekaihua,项目名称:StudyTest,代码行数:17,代码来源:10-17.php
示例14: _unserializeRecurser
/**
* _unserializeRecurser()
*
* This method will be used to traverse the depths of the structure
* as needed to *unserialize* the profile from an xmlIterator
*
* @param SimpleXMLIterator $xmlIterator
* @param Zend_Tool_Project_Profile_Resource $resource
*/
protected function _unserializeRecurser(SimpleXMLIterator $xmlIterator, Zend_Tool_Project_Profile_Resource $resource = null)
{
foreach ($xmlIterator as $resourceName => $resourceData) {
$contextName = $resourceName;
$subResource = new Zend_Tool_Project_Profile_Resource($contextName);
$subResource->setProfile($this->_profile);
if ($resourceAttributes = $resourceData->attributes()) {
$attributes = array();
foreach ($resourceAttributes as $attrName => $attrValue) {
$attributes[$attrName] = (string) $attrValue;
}
$subResource->setAttributes($attributes);
}
if ($resource) {
$resource->append($subResource, false);
} else {
$this->_profile->append($subResource);
}
if ($this->_contextRepository->isOverwritableContext($contextName) == false) {
$subResource->initializeContext();
}
if ($xmlIterator->hasChildren()) {
self::_unserializeRecurser($xmlIterator->getChildren(), $subResource);
}
}
}
开发者ID:c12g,项目名称:stratos-php,代码行数:35,代码来源:Xml.php
示例15: ParseXML
private function ParseXML($data_content)
{
$xmlIterator = new SimpleXMLIterator($data_content);
$xmlIterator->rewind();
$xmlIterator->next();
while ($xmlIterator->current() != Null) {
$current = $xmlIterator->current();
$Item = $this->ParsePerItem($current);
$Parsed[$Item["sku"]] = $Item;
$xmlIterator->next();
}
return $Parsed;
}
开发者ID:blaz1988,项目名称:presta,代码行数:13,代码来源:uploadxml.php
示例16: parseXML
/**
* Converts a SimpleXMLIterator structure into an associative array.
*
* Used to parse an XML response from Mollom servers into a PHP array. For
* example:
* @code
* $elements = new SimpleXmlIterator($response_body);
* $parsed_response = $this->parseXML($elements);
* @endcode
*
* @param SimpleXMLIterator $sxi
* A SimpleXMLIterator structure of the server response body.
*
* @return array
* An associative, possibly multidimensional array.
*/
public static function parseXML(SimpleXMLIterator $sxi)
{
$a = array();
$remove = array();
for ($sxi->rewind(); $sxi->valid(); $sxi->next()) {
$key = $sxi->key();
// Recurse into non-scalar values.
if ($sxi->hasChildren()) {
$value = self::parseXML($sxi->current());
} else {
$value = strval($sxi->current());
}
if (!isset($a[$key])) {
$a[$key] = $value;
} else {
// First time we reach here, convert the existing keyed item. Do not
// remove $key, so we enter this path again.
if (!isset($remove[$key])) {
$a[] = $a[$key];
// Mark $key for removal.
$remove[$key] = $key;
}
// Add the new item.
$a[] = $value;
}
}
// Lastly, remove named keys that have been converted to indexed keys.
foreach ($remove as $key) {
unset($a[$key]);
}
return $a;
}
开发者ID:SatiricMan,项目名称:addons,代码行数:48,代码来源:class.mollom.php
示例17: simplexmlToArray
/**
* Converts SimpleXMLIterator object into an array.
* @param SimpleXMLIterator $xmlIterator
* @return string[]
*/
public function simplexmlToArray($xmlIterator)
{
$xmlStringArray = array();
for ($xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next()) {
if ($xmlIterator->hasChildren()) {
$object = $xmlIterator->current();
$xmlStringArray[$object->getName()] = $this->simplexmlToArray($object);
} else {
$object = $xmlIterator->current();
$xmlStringArray[$object->getName()] = (string) $xmlIterator->current();
}
}
return $xmlStringArray;
}
开发者ID:rabbitdigital,项目名称:HRM,代码行数:19,代码来源:ReportGeneratorService.php
示例18: _unserializeRecurser
protected function _unserializeRecurser(SimpleXMLIterator $projectProfileIterator, Zend_Tool_Provider_ZfProject_ProjectContext_ProjectContextAbstract $context = null)
{
foreach ($projectProfileIterator as $projectProfileNodeName => $projectProfileNode) {
$subContextClass = self::getContextByName($projectProfileNodeName);
$subContext = new $subContextClass();
if ($subContext->getContextName() === 'projectProfileFile') {
$subContext->setProjectProfile($this);
}
if ($attributes = $projectProfileNode->attributes()) {
foreach ($attributes as $attrName => $attrValue) {
$clnAttrs[$attrName] = (string) $attrValue;
}
$subContext->setParameters($clnAttrs);
}
if ($context) {
$context->append($subContext);
} else {
$this->appendProjectContext($subContext);
}
if ($projectProfileIterator->hasChildren()) {
self::_unserializeRecurser($projectProfileIterator->getChildren(), $subContext);
}
}
}
开发者ID:jorgenils,项目名称:zend-framework,代码行数:24,代码来源:ProjectProfile.php
示例19: processValueOnly
/**
* @param \SimpleXMLIterator $sxi
*
* @param string $tableName
* @param string $xpath
*/
protected function processValueOnly(\SimpleXMLIterator $sxi, string $tableName, string $xpath = '//result/child::*[not(*|@*|self::dataTime)]')
{
$items = $sxi->xpath($xpath);
if (false === $items || 0 === count($items)) {
return;
}
/**
* @var \SimpleXMLElement[] $items
*/
$columns = [];
foreach ($items as $ele) {
$name = (string) $ele->getName();
$columns[$name] = $this->inferTypeFromName($name, true);
}
uksort($columns, function ($alpha, $beta) {
return strtolower($alpha) <=> strtolower($beta);
});
$this->tables[$tableName] = ['values' => $columns];
}
开发者ID:yapeal,项目名称:yapeal-ng,代码行数:25,代码来源:Creator.php
示例20: getChildrenValues
/**
* @param \SimpleXMLIterator $element
* @param \Twig_Template $template
*
* @param string $formId
* @param string $xPath
* @param string $requiredChildren
* @param array $identityRefs
*
* @return array|bool
*/
public function getChildrenValues($element, $template, $formId, $xPath = "", $requiredChildren = "", $identityRefs = array())
{
$retArr = array();
$targetAttributes = array('key', 'iskey', 'mandatory');
foreach ($element as $label => $el) {
$attributesArr = array_fill_keys($targetAttributes, false);
foreach ($element->attributes() as $name => $attr) {
if ($name == "key") {
$attributesArr[$name] = (string) $attr[0];
}
}
foreach ($el->attributes() as $name => $attr) {
if (in_array($name, array('iskey', 'mandatory'))) {
$attributesArr[$name] = (string) $attr[0];
}
}
if (($attributesArr['iskey'] !== "true" && $attributesArr['key'] == false || $requiredChildren !== "" && $label != $requiredChildren) && $attributesArr['mandatory'] == false) {
continue;
}
if ($attributesArr['key'] !== false) {
$requiredChildren = $attributesArr['key'];
} else {
$requiredChildren = "";
}
$twigArr = array();
$twigArr['key'] = "";
$twigArr['xpath'] = "";
$twigArr['element'] = $el;
$twigArr['useHiddenInput'] = true;
$twigArr['moduleIdentityRefs'] = $identityRefs;
$newXPath = $xPath . "/*";
$res = $this->getAvailableLabelValuesForXPath($formId, $newXPath);
$retArr[$label] = array();
if (isset($res['labelsAttributes'][$label])) {
$retArr[$label]['labelAttributes'] = $res['labelsAttributes'][$label];
}
$retArr[$label]['valueElem'] = $this->removeMultipleWhitespaces($template->renderBlock('configInputElem', $twigArr));
$retArr[$label]['children'] = $this->getChildrenValues($el, $template, $formId, $newXPath, $requiredChildren);
}
return sizeof($retArr) ? $retArr : false;
}
开发者ID:Barathi07,项目名称:Netopeer-GUI,代码行数:52,代码来源:XMLoperations.php
注:本文中的SimpleXMLIterator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论