本文整理汇总了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;
}
}
示例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];
}
示例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());
}
示例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()) {
示例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();
}
示例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>';
}