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


PHP SimpleXMLIterator::xpath方法代码示例

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


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

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

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

示例3: SimpleXMLIterator

    </animal>
</document>
XML;
try {
    // load the XML Iterator and iterate over it
    $sxi = new SimpleXMLIterator($xmlstring);
    // iterate over animals
    foreach ($sxi as $animal) {
        // iterate over category nodes
        foreach ($animal as $key => $category) {
            echo $category->species . PHP_EOL;
        }
    }
} catch (Exception $e) {
    die($e->getMessage());
}
echo '===================================' . PHP_EOL;
echo 'Finding all species with xpath' . PHP_EOL;
echo '===================================' . PHP_EOL;
// which can also be re-written for optimization
try {
    // load the XML Iterator and iterate over it
    $sxi = new SimpleXMLIterator($xmlstring);
    // use xpath
    $foo = $sxi->xpath('animal/category/species');
    foreach ($foo as $k => $v) {
        echo $v . PHP_EOL;
    }
} catch (Exception $e) {
    die($e->getMessage());
}
开发者ID:pixlr,项目名称:ZCE-PHP-Cert,代码行数:31,代码来源:simplexml-iterator.php

示例4: while

        //echo $name, '=>', $data, "<br />";
    }
    // while 循环
    $simpleIt->rewind();
    while ($simpleIt->valid()) {
        /*var_dump($simpleIt->key());
          echo '=>';
          var_dump($simpleIt->current());*/
        // getChildren() 获得当前节点的子节点
        if ($simpleIt->hasChildren()) {
            //var_dump($simpleIt->getChildren());
        }
        $simpleIt->next();
    }
    // xpath 可以通过path直接获得指定节点的值
    var_dump($simpleIt->xpath('animal/category/species'));
} catch (Exception $e) {
    echo $e->getMessage();
}
echo '--------------------------------- SimpleXMLIterator END-----------------------------------', '<br />';
echo '--------------------------------- CachingIterator START-----------------------------------', '<br />';
/**
 * CachingIterator 提前读取一个元素
 * 可以用于确定当前元素是否为最后一个元素
 */
$array = array('koala', 'kangaroo', 'wombat', 'wallaby', 'emu', 'kiwi', 'kookaburra', 'platypus');
try {
    $cachingIt = new CachingIterator(new ArrayIterator($array));
    foreach ($cachingIt as $item) {
        echo $item;
        if ($cachingIt->hasNext()) {
开发者ID:ray0916,项目名称:learn,代码行数:31,代码来源:iterator.php

示例5: saveAction

 /**
  * Extending the save action for custom attributes
  * check the orders, move order to higher rank and swap
  * @return void
  * @author Mudassar Mumtaz
  */
 public function saveAction()
 {
     $data = array();
     $result = new \SimpleXMLIterator($_POST['data']);
     $fieldset = $result->xpath("//*[contains(local-name(),'fieldset')]")[0];
     $data['order'] = (int) $fieldset->label_order;
     $data['section'] = (string) $fieldset->label_section;
     $phpMethod = 'updateSectionOrder';
     if ((string) $fieldset->label_customattribute_id != '') {
         $data['id'] = (string) $fieldset->label_customattribute_id;
         $phpMethod = 'swapSectionOrder';
     }
     $this->_queueMessage(['phpMethod' => $phpMethod, 'phpClass' => 'MoveIn4CustomAttribute\\Model\\CustomAttribute', 'phpData' => $data]);
     $this->saveHelper($this->_formXml, $this->_handler, $this->_formCollection, true);
     return $this->setresponse();
 }
开发者ID:EngrHaiderAli,项目名称:movein-ui,代码行数:22,代码来源:CustomAttributeController.php

示例6: SimpleXMLIterator

\t\t\t<my:title>Крутая Сандра</my:title>
\t\t\t<title>XML. Справочник</title>
\t\t\t<price>100</price>
\t\t</category>
\t</book>
</catalog>
XML;
?>

<?php 
/*
$sxi =new SimpleXMLIterator($xmlstring);

$foo = $sxi->xpath('/catalog/book/category/title');

foreach ($foo as $k=>$v){
	echo $v.'<br />';
}
*/
?>

<?php 
$sxi = new SimpleXMLIterator($xmlstring);
//$sxi-> registerXPathNamespace('my', 'http://mysuperpupermegasite.ru/catalog');
$result = $sxi->xpath('//my:title');
foreach ($sxi->getDocNamespaces('book') as $ns) {
    echo $ns . '<br>';
}
foreach ($result as $k => $v) {
    echo $v . '<br>';
}
开发者ID:ralf000,项目名称:PHP4,代码行数:31,代码来源:103-simpleXMLIterator-3.php


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