本文整理汇总了PHP中SimpleXMLElement::xpath方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::xpath方法的具体用法?PHP SimpleXMLElement::xpath怎么用?PHP SimpleXMLElement::xpath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::xpath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseSDSS
function parseSDSS($output)
{
$xml = new SimpleXMLElement($output);
$xpath_run = "//field[@col='run']";
$xpath_camcol = "//field[@col='camcol']";
$xpath_rerun = "//field[@col='rerun']";
$xpath_field = "//field[@col='field']";
$out_run = $xml->xpath($xpath_run);
$out_camcol = $xml->xpath($xpath_camcol);
$out_rerun = $xml->xpath($xpath_rerun);
$out_field = $xml->xpath($xpath_field);
$imagefields = array();
$i = 0;
while (list(, $node) = each($out_run)) {
$imagefields[$i] = array(trim($node), 0);
$i++;
}
$i = 0;
while (list(, $node) = each($out_camcol)) {
$imagefields[$i][1] = trim($node);
$i++;
}
$i = 0;
while (list(, $node) = each($out_rerun)) {
$imagefields[$i][2] = trim($node);
$i++;
}
$i = 0;
while (list(, $node) = each($out_field)) {
$imagefields[$i][3] = trim($node);
$i++;
}
return $imagefields;
}
示例2: fromSimpleXMLElement
/**
* @param \SimpleXMLElement $node
* @param $structureExtensionId extension of structures.xml
* @return static
*/
public static function fromSimpleXMLElement(\SimpleXMLElement $node, $structureExtensionId)
{
$url = isset($node['url']) ? (string) $node['url'] : '#';
if ($url == '#' || empty($url)) {
$extension = null;
$controller = null;
$action = null;
} else {
$parts = explode('/', trim($url, '/'));
$parts = array_replace(array_fill(0, 3, null), $parts);
list($extension, $controller, $action) = $parts;
}
$data = array('id' => (string) $node['id'], 'name' => (string) $node['name'], 'url' => $url, 'extension' => $extension, 'controller' => $controller, 'action' => $action, 'binding' => isset($node['binding']) ? (string) $node['binding'] : null, 'policy' => isset($node['policy']) ? (string) $node['policy'] : self::POLICY_MERGE, 'disabled' => isset($node['disabled']) ? true : false);
$trees = array();
foreach ($node->xpath("trees/tree") as $treeNode) {
$trees[] = Tree::fromSimpleXMLElement($treeNode, $structureExtensionId);
}
$actions = array();
foreach ($node->xpath("actions/action") as $actionNode) {
$actions[] = Action::fromSimpleXMLElement($actionNode, $structureExtensionId);
}
$includeClassActions = isset($node->actions) && isset($node->actions['allowClassActions']) && $node->actions['allowClassActions'] == 'true';
if ($includeClassActions) {
foreach ($trees as $tree) {
$rootNodeUri = $tree->get('rootNode');
if (!empty($rootNodeUri)) {
$rootNode = new \core_kernel_classes_Class($rootNodeUri);
foreach (ClassActionRegistry::getRegistry()->getClassActions($rootNode) as $action) {
$actions[] = $action;
}
}
}
}
return new static($data, $trees, $actions);
}
示例3: parseBody
/**
* Parses additional exception information from the response body
*
* @param \SimpleXMLElement $body The response body as XML
* @param array $data The current set of exception data
*/
protected function parseBody(\SimpleXMLElement $body, array &$data)
{
$data['parsed'] = $body;
$namespaces = $body->getDocNamespaces();
if (isset($namespaces[''])) {
// Account for the default namespace being defined and PHP not being able to handle it :(
$body->registerXPathNamespace('ns', $namespaces['']);
$prefix = 'ns:';
} else {
$prefix = '';
}
if ($tempXml = $body->xpath("//{$prefix}Code[1]")) {
$data['code'] = (string) $tempXml[0];
}
if ($tempXml = $body->xpath("//{$prefix}Message[1]")) {
$data['message'] = (string) $tempXml[0];
}
$tempXml = $body->xpath("//{$prefix}RequestId[1]");
if (empty($tempXml)) {
$tempXml = $body->xpath("//{$prefix}RequestID[1]");
}
if (isset($tempXml[0])) {
$data['request_id'] = (string) $tempXml[0];
}
}
示例4: getReleaseInfo
/**
*
* @access private
* @author "Lionel Lecaque, <lionel@taotesting.com>"
* @param SimpleXMLElement $releaseNode
* @return array
*/
private function getReleaseInfo($releaseNode)
{
$versionNode = $releaseNode->xpath('version');
$commentNode = $releaseNode->xpath('comment');
$patchs = $releaseNode->xpath('patchs');
$returnValue = array('version' => (string) $versionNode[0], 'comment' => (string) trim($commentNode[0]));
if (!empty($patchs)) {
foreach ($patchs[0] as $patch) {
$patchNode = $patch->xpath('version');
$patchNodeValue = (string) $patchNode[0];
$returnValue['patchs'][$patchNodeValue] = $this->getReleaseInfo($patch);
}
}
$extensions = $releaseNode->xpath('extensions');
if (!empty($extensions)) {
foreach ($extensions[0] as $extension) {
$returnValue['extensions'][] = (string) $extension;
}
}
$messages = $releaseNode->xpath('messages');
if (!empty($messages)) {
foreach ($messages[0] as $message) {
$returnValue['messages'][$message->getName()][] = (string) $message;
}
} else {
$returnValue['messages'] = array();
}
return $returnValue;
}
示例5: getSVGMetadata
function getSVGMetadata($infile)
{
if (!($fileContent = file_get_contents($infile))) {
return -1;
}
// can't access file
$svgMetaRoot = '/svg:svg/svg:metadata/rdf:RDF/cc:Work';
$svgElements = ['Title' => 'dc:title', 'Date' => 'dc:date', 'Publisher' => 'dc:publisher/cc:Agent/dc:title', 'Language' => 'dc:language', 'Description' => 'dc:description'];
$meta = [];
$xml = new SimpleXMLElement($fileContent);
if (!$xml->xpath($svgMetaRoot)) {
return false;
}
// metadata block not found
foreach ($svgElements as $title => $path) {
$el = $xml->xpath("{$svgMetaRoot}/{$path}");
$meta[$title] = $el ? $el[0]->__toString() : '';
}
// getting keywords
$meta['Tags'] = '';
$svgKeywords = $xml->xpath("{$svgMetaRoot}/dc:subject/rdf:Bag/rdf:li");
if ($svgKeywords) {
foreach ($svgKeywords as $keyword) {
$keyword = trim($keyword->__toString());
if ($keyword) {
$meta['Tags'] .= "{$keyword}, ";
}
}
$meta['Tags'] = substr($meta['Tags'], 0, -2);
}
$meta = array_map('trim', $meta);
return $meta;
}
示例6: readFromVariable
/**
* @param string $data
* @param string $element
* @return array Parsed data.
*/
public function readFromVariable($data, $element = 'target')
{
$messages = array();
$mangler = $this->group->getMangler();
$reader = new SimpleXMLElement($data);
$reader->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
$items = array_merge($reader->xpath('//trans-unit'), $reader->xpath('//xliff:trans-unit'));
foreach ($items as $item) {
/** @var SimpleXMLElement $source */
$source = $item->{$element};
if (!$source) {
continue;
}
$key = (string) $item['id'];
/* In case there are tags inside the element, preserve
* them. */
$dom = new DOMDocument('1.0');
$dom->loadXML($source->asXml());
$value = self::getInnerXml($dom->documentElement);
/* This might not be 100% according to the spec, but
* for now if there is explicit approved=no, mark it
* as fuzzy, but don't do that if the attribute is not
* set */
if ((string) $source['state'] === 'needs-l10n') {
$value = TRANSLATE_FUZZY . $value;
}
// Strip CDATA if present
$value = preg_replace('/<!\\[CDATA\\[(.*?)\\]\\]>/s', '\\1', $value);
$messages[$key] = $value;
}
return array('MESSAGES' => $mangler->mangle($messages));
}
示例7: construct_postProcessRecordId
/**
* Hook for the __construct() method of dlf/common/class.tx_dlf_document.php
* When using Goobi.Production the record identifier is saved only in MODS, but not
* in METS. To get it anyway, we have to do some magic.
*
* @access public
*
* @param SimpleXMLElement &$xml: The XML object
* @param mixed $record_id: The record identifier
*
* @return void
*/
public function construct_postProcessRecordId(SimpleXMLElement &$xml, &$record_id)
{
if (!$record_id) {
$xml->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3');
if ($divs = $xml->xpath('//mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID]')) {
$smLinks = $xml->xpath('//mets:structLink/mets:smLink');
if ($smLinks) {
foreach ($smLinks as $smLink) {
$links[(string) $smLink->attributes('http://www.w3.org/1999/xlink')->from][] = (string) $smLink->attributes('http://www.w3.org/1999/xlink')->to;
}
foreach ($divs as $div) {
if (!empty($links[(string) $div['ID']])) {
$id = (string) $div['DMDID'];
break;
}
}
}
if (empty($id)) {
$id = (string) $divs[0]['DMDID'];
}
$recordIds = $xml->xpath('//mets:dmdSec[@ID="' . $id . '"]//mods:mods/mods:recordInfo/mods:recordIdentifier');
if (!empty($recordIds[0])) {
$record_id = (string) $recordIds[0];
}
}
}
}
示例8: testFormaterReturnsXml
public function testFormaterReturnsXml()
{
// all results
$rs1 = $this->getMockBuilder('\\Hal\\Component\\Result\\ResultSet')->disableOriginalConstructor()->getMock();
$rs1->expects($this->any())->method('asArray')->will($this->returnValue(array('volume' => 5)));
$rs1->expects($this->any())->method('getFilename')->will($this->returnValue('path2/file1.php'));
$rs2 = $this->getMockBuilder('\\Hal\\Component\\Result\\ResultSet')->disableOriginalConstructor()->getMock();
$rs2->expects($this->any())->method('asArray')->will($this->returnValue(array('volume' => 15)));
$rs2->expects($this->any())->method('getFilename')->will($this->returnValue('path1/file1.php'));
$collection = $this->getMockBuilder('\\Hal\\Component\\Result\\ResultCollection')->disableOriginalConstructor()->getMock();
$collection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator(array($rs1, $rs2))));
$collection->expects($this->any())->method('getFilename')->will($this->returnValue('abc'));
$collection->expects($this->any())->method('asArray')->will($this->returnValue(array(array('volume' => 5), array('volume' => 15))));
$bounds = new Bounds();
// grouped results
$groupedResults = new ResultCollection();
$result = $this->getMockBuilder('\\Hal\\Component\\Result\\ResultAggregate')->disableOriginalConstructor()->getMock();
$result->expects($this->any())->method('getName')->will($this->returnValue('path1'));
$result->expects($this->any())->method('getBounds')->will($this->returnValue($this->getMock('\\Hal\\Component\\Bounds\\Result\\ResultInterface')));
$groupedResults->push($result);
$result = $this->getMockBuilder('\\Hal\\Component\\Result\\ResultAggregate')->disableOriginalConstructor()->getMock();
$result->expects($this->any())->method('getName')->will($this->returnValue('path2'));
$result->expects($this->any())->method('getBounds')->will($this->returnValue($this->getMock('\\Hal\\Component\\Bounds\\Result\\ResultInterface')));
$groupedResults->push($result);
// formater
$validator = $this->getMockBuilder('\\Hal\\Application\\Rule\\Validator')->disableOriginalConstructor()->getMock();
$formater = new Xml($validator, $bounds, $this->getMockBuilder('\\Hal\\Application\\Extension\\ExtensionService')->disableOriginalConstructor()->getMock());
$output = $formater->terminate($collection, $groupedResults);
$xml = new \SimpleXMLElement($output);
$p = $xml->xpath('//project');
$this->assertEquals('10', $p[0]['volume']);
$m = $xml->xpath('//project/modules/module[@namespace="path1"]');
$m = $m[0];
$this->assertCount(2, $xml->xpath('//project/modules/module'));
}
示例9: smwf_ti_update
function smwf_ti_update($tiArticleName)
{
global $smwgDIIP;
require_once $smwgDIIP . "/specials/TermImport/SMW_WIL.php";
$xmlString = smwf_om_GetWikiText('TermImport:' . $tiArticleName);
$start = strpos($xmlString, "<ImportSettings>");
$end = strpos($xmlString, "</ImportSettings>") + 17 - $start;
$xmlString = substr($xmlString, $start, $end);
$simpleXMLElement = new SimpleXMLElement($xmlString);
$moduleConfig = $simpleXMLElement->xpath("//ModuleConfiguration");
$moduleConfig = trim($moduleConfig[0]->asXML());
$dataSource = $simpleXMLElement->xpath("//DataSource");
$dataSource = trim($dataSource[0]->asXML());
$mappingPolicy = $simpleXMLElement->xpath("//MappingPolicy");
$mappingPolicy = trim($mappingPolicy[0]->asXML());
$conflictPolicy = $simpleXMLElement->xpath("//ConflictPolicy");
$conflictPolicy = trim($conflictPolicy[0]->asXML());
$inputPolicy = $simpleXMLElement->xpath("//InputPolicy");
$inputPolicy = trim($inputPolicy[0]->asXML());
$importSets = $simpleXMLElement->xpath("//ImportSets");
$importSets = trim($importSets[0]->asXML());
$wil = new WIL();
$terms = $wil->importTerms($moduleConfig, $dataSource, $importSets, $inputPolicy, $mappingPolicy, $conflictPolicy, $tiArticleName, true);
if ($terms != wfMsg('smw_ti_import_successful')) {
return $terms;
} else {
return "success";
}
}
示例10: getData
public function getData($parsed)
{
$video_id = $parsed['video_id'];
$buffer = file_get_contents("http://www.metacafe.com/api/item/{$video_id}");
$xml = new SimpleXMLElement($buffer);
return array('title' => current($xml->xpath('/rss/channel/item/title')), 'description' => strip_tags(current($xml->xpath('/rss/channel/item/description'))), 'thumbnail' => current($xml->xpath('/rss/channel/item/media:thumbnail/@url')), 'embedurl' => current($xml->xpath('/rss/channel/item/media:content/@url')));
}
示例11: fetchData
public function fetchData()
{
$rss = $this->_getRss();
if ($rss) {
$xml = new \SimpleXMLElement($rss);
// Ветер
$tmp = $xml->xpath('/rss/channel/yweather:wind');
if ($tmp === false) {
throw new \Exception("Error parsing XML.");
}
$this->_wind = $tmp[0];
// Текущая температура воздуха и погода
$tmp = $xml->xpath('/rss/channel/item/yweather:condition');
if ($tmp === false) {
throw new \Exception("Error parsing XML.");
}
$tmp = $tmp[0];
$this->_temperature = $tmp['temp'];
$this->_condition = (int) $tmp['code'];
$this->_forecasts = $xml->xpath('/rss/channel/item/yweather:forecast');
//$this->condition_text = strtolower((string)$tmp['text']);
$location = $xml->xpath('/rss/channel/yweather:location');
$this->_city = (string) $location[0]['city'];
return true;
}
return false;
}
示例12: _processRewrites
/**
* Processes the rewrites on the all of the config.xmls in a given path
*
* @return void
*/
protected function _processRewrites()
{
$baseIter = new RecursiveDirectoryIterator($this->_basePath());
$recurse = new RecursiveIteratorIterator($baseIter);
$configs = new RegexIterator($recurse, '/config\\.xml$/');
$reportsObserver = $this->_reportObserver();
foreach ($configs as $configFile) {
$this->_writeLine("Consuming file {$configFile}");
$xml = new SimpleXMLElement($configFile, 0, true);
$models = $xml->xpath('//models/*/rewrite');
foreach ($models as $model) {
foreach (get_object_vars($model) as $key => $class) {
$this->_writeLine("|_ Found model rewrite {$key}: {$class}");
}
}
$block = $xml->xpath('//blocks/*/rewrite');
foreach ($blocks as $block) {
foreach (get_object_vars($block) as $key => $path) {
$this->_writeLine("|_ Found block rewrite {$key}: {$path}");
}
}
if ($reportsObserver) {
$events = $xml->xpath('//events');
foreach ($events as $observers) {
foreach ($observers->children() as $event) {
$this->_writeLine("|_ Found observer(s) for {$event->getName()}:");
foreach ($event->xpath('observers/*') as $observer) {
$this->_writeLine("|__ Observer {$observer->getName()}: {$observer->class->__toString()}::{$observer->method->__toString()}");
}
}
}
}
}
}
示例13: buscarPorTag
function buscarPorTag($tag)
{
#Using the tag we complete the url
$flickr = "https://api.flickr.com/services/feeds/photos_public.gne?tags=" . $tag;
#With the complete url we obtain the xml content
$xml = file_get_contents($flickr);
#Create a simple xml element using the xml data obtained
$entradas = new SimpleXMLElement($xml);
#The namespace is registered for the xpath search
$entradas->registerXPathNamespace("feed", "http://www.w3.org/2005/Atom");
#Printing the header
echo "<h1 align='center'>Últimas 10 fotos con la etiqueta " . $tag . "</h1><table>";
#Declaring the string for the table creation beginning for the header
$tabla = "<th colspan='2'>¿Quieres buscar por otra etiqueta?<br><pre>Para usar varias separar con coma(sin espacios)</pre><form method='get'>\t\t\t\n\t\t\t<input type='text'name='tag'><br><input type='submit' value='Aceptar'>\n\t\t\t</form><th>";
#Getting links with xpath expression
$lauthor = $entradas->xpath("//feed:entry/feed:author/feed:name");
$links = $entradas->xpath("//feed:entry/feed:link[@rel='enclosure']/@href");
#We make a loop for showing the results
for ($i = 0; $i < 10; $i++) {
#we add the xml data to the table creation string, navigating through the document and using the previously created array
$tabla = $tabla . "<tr><td><a href='" . $links[$i] . "'><img src=" . $links[$i] . " width='500px'></a></td><td width='300px'><b>Título</b><br>" . $entradas->entry[$i]->title . "<br><b>Autor</b></br>" . $entradas->entry[$i]->author->name . "</td></tr>";
}
#Finally we print the complete table
echo "<table align='center'bgcolor='#F2F2F2' cellpadding='20px'>" . $tabla . "</table>";
}
示例14: getData
public function getData($parsed)
{
$video_id = $parsed['video_id'];
$buffer = file_get_contents('http://blip.tv' . $video_id . '?skin=rss');
$xml = new SimpleXMLElement($buffer);
return array('title' => current($xml->xpath('/rss/channel/item/title')), 'description' => strip_tags(current($xml->xpath('/rss/channel/item/description'))), 'thumbnail' => current($xml->xpath('/rss/channel/item/media:thumbnail/@url')), 'embedurl' => current($xml->xpath('/rss/channel/item/blip:embedUrl')));
}
示例15: getObject
/**
* This method returns an object matching the description specified by the element.
*
* @access public
* @param Spring\Object\Parser $parser a reference to the parser
* @param \SimpleXMLElement $element the element to be parsed
* @return mixed an object matching the description
* specified by the element
* @throws Throwable\Parse\Exception indicates that a problem occurred
* when parsing
*/
public function getObject(Spring\Object\Parser $parser, \SimpleXMLElement $element)
{
$attributes = $element->attributes();
$type = isset($attributes['type']) ? $parser->valueOf($attributes['type']) : '\\Unicity\\BT\\Task\\Semaphore';
$element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI);
$children = $element->xpath('./spring-bt:blackboard');
$blackboard = !empty($children) ? $parser->getObjectFromElement($children[0]) : null;
$element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI);
$children = $element->xpath('./spring-bt:policy');
$policy = !empty($children) ? $parser->getObjectFromElement($children[0]) : null;
$object = new $type($blackboard, $policy);
if (!$object instanceof BT\Task\Semaphore) {
throw new Throwable\Parse\Exception('Invalid type defined. Expected a task semaphore, but got an element of type ":type" instead.', array(':type' => $type));
}
if (isset($attributes['title'])) {
$object->setTitle($parser->valueOf($attributes['title']));
}
$element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI);
$children = $element->xpath('./spring-bt:tasks');
if (!empty($children)) {
foreach ($children as $child) {
$object->addTasks($parser->getObjectFromElement($child));
}
}
return $object;
}