本文整理汇总了PHP中SimpleXmlElement::xpath方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXmlElement::xpath方法的具体用法?PHP SimpleXmlElement::xpath怎么用?PHP SimpleXmlElement::xpath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXmlElement
的用法示例。
在下文中一共展示了SimpleXmlElement::xpath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseArtifact
/**
* {@inheritDoc}
*/
public function parseArtifact(Build $build, $artifact)
{
$this->build = $build;
$this->artifact = $artifact ? new \SimpleXMLElement($artifact) : false;
$this->details['totalMethods'] = 0;
$this->details['totalStatements'] = 0;
$this->details['totalConditionals'] = 0;
$this->details['coveredMethods'] = 0;
$this->details['coveredStatements'] = 0;
$this->details['coveredConditionals'] = 0;
$this->details['total'] = 0;
$this->details['covered'] = 0;
if ($this->artifact) {
foreach ($this->artifact->xpath('//file/class/metrics') as $metric) {
$this->details['totalMethods'] += (int) $metric['methods'];
$this->details['totalStatements'] += (int) $metric['statements'];
$this->details['totalConditionals'] += (int) $metric['conditionals'];
$this->details['coveredMethods'] += (int) $metric['coveredmethods'];
$this->details['coveredStatements'] += (int) $metric['coveredstatements'];
$this->details['coveredConditionals'] += (int) $metric['coveredconditionals'];
$this->details['total'] += (int) $metric['methods'] + (int) $metric['statements'] + (int) $metric['conditionals'];
$this->details['covered'] += (int) $metric['coveredmethods'] + (int) $metric['coveredstatements'] + (int) $metric['coveredconditionals'];
}
}
$this->calculateTotals();
if ($build->getParent()) {
$parent = $build->getParent();
$statistics = $parent->getFlatStatistics();
$this->generateCoverageComparisonStatistics($statistics);
}
}
示例2: getSimpleTextResult
/**
* {@inheritDoc}
*/
public function getSimpleTextResult()
{
$violationCount = 0;
if ($this->artifact) {
foreach ($this->artifact->xpath('//file') as $file) {
foreach ($file->xpath('//violation') as $violation) {
$violationCount++;
}
}
$result = $violationCount . ' instance' . ($violationCount > 1 ? 's ' : ' ') . "of messy code found\n";
} else {
$result = "No Messy Code Detected\n";
}
return $result;
}
示例3: explodeXML
function explodeXML($xml)
{
$objXML = new SimpleXmlElement($xml);
if (strpos($xml, 'soap:') !== false) {
$objXML->registerXPathNamespace('soap', 'http://www.portalfiscal.inf.br/nfe/wsdl/NfeConsulta2');
$xml2 = (array) $objXML->xpath('//soap:Body');
} else {
$objXML->registerXPathNamespace('soapenv', 'http://www.w3.org/2003/05/soap-envelope');
$xml2 = $objXML->xpath('//soapenv:Body');
}
$xml2[0]->children()->children()->children()->cStat;
$xml2[0]->children()->children()->children()->xMotivo;
$xml2[0]->children()->children()->children()->protNFe->infProt->dhRecbto;
$xml2[0]->children()->children()->children()->protNFe->infProt->nProt;
}
示例4: logBuildExceptions
/**
* Log any build exceptions from the CheckStyle report.
*/
public function logBuildExceptions()
{
if ($this->artifact) {
foreach ($this->artifact->xpath('//file') as $file) {
foreach ($file->xpath('//error') as $error) {
$exception = new Build\BuildException();
$exception->setAsset(basename($file['name']));
$exception->setReference($error['line']);
$exception->setType('E');
$exception->setMessage($error['message']);
$this->build->addException($exception);
}
}
}
}
示例5: parseLinks
/**
* Parse Links
*
* Parses an XML file returned by a link resolver
* and converts it to a standardised format for display
*
* @param string $xmlstr Raw XML returned by resolver
*
* @return array Array of values
*/
public function parseLinks($xmlstr)
{
$records = [];
// array to return
try {
$xml = new \SimpleXmlElement($xmlstr);
} catch (\Exception $e) {
return $records;
}
$root = $xml->xpath("//ctx_obj_targets");
$xml = $root[0];
foreach ($xml->children() as $target) {
$record = [];
$record['title'] = (string) $target->target_public_name;
$record['href'] = (string) $target->target_url;
$record['service_type'] = (string) $target->service_type;
if (isset($target->coverage->coverage_text)) {
$coverageText =& $target->coverage->coverage_text;
$record['coverage'] = (string) $coverageText->threshold_text->coverage_statement;
if (isset($coverageText->embargo_text->embargo_statement)) {
$record['coverage'] .= ' ' . (string) $coverageText->embargo_text->embargo_statement;
$record['embargo'] = (string) $coverageText->embargo_text->embargo_statement;
}
}
if (isset($target->coverage)) {
$record['coverage_details'] = json_decode(json_encode($target->coverage), true);
}
array_push($records, $record);
}
return $records;
}
示例6: getSimpleTextResult
/**
* {@inheritDoc}
*/
public function getSimpleTextResult()
{
$totalTests = 0;
$totalAssertions = 0;
$totalFailures = 0;
$totalErrors = 0;
if ($this->artifact) {
foreach ($this->artifact->xpath('//testsuite') as $suite) {
$totalTests += (int) $suite['tests'];
$totalAssertions += (int) $suite['assertions'];
$totalFailures += (int) $suite['failures'];
$totalErrors += (int) $suite['errors'];
}
}
$result = 'PHPUnit tests ' . ($totalErrors + $totalFailures > 0 ? 'failed' : 'passed') . ".\n\n" . "Tests: " . $totalTests . "\n" . "Assertions: " . $totalAssertions . "\n" . "Failures: " . $totalFailures . "\n" . "Errors: " . $totalErrors . "\n";
return $result;
}
示例7: getLayoutUpdates
public function getLayoutUpdates()
{
$updates = $this->xml->xpath('//layout/updates/*');
$res = array();
foreach ($updates as $update) {
$res[$update->getName()] = array('file' => (string) $update->file, 'area' => (string) $update->xpath('../../..')[0]->getName());
}
return $res;
}
示例8: getBlogPosts
public function getBlogPosts(SimpleXmlElement $xml)
{
$blogs = array();
$natureBlogs = $xml->xpath("//source[@source='Nature']/citations/citation");
if ($natureBlogs) {
foreach ($natureBlogs as $citation) {
$blog = array();
$blog['uri'] = (string) $citation->attributes()->uri;
$blog['from'] = "Nature via Plos";
$blog['pubDate'] = date('c', strtotime($citation->post[0]->attributes()->created_at));
$blog['title'] = (string) $citation->post[0]->attributes()->title;
$blog['natureBlogId'] = (string) $citation->post[0]->attributes()->blog_id;
$blogs[] = $blog;
}
}
$postGenomicBlogs = $xml->xpath("//source[@source='Postgenomic']/citations/citation");
if ($postGenomicBlogs) {
foreach ($postGenomicBlogs as $citation) {
$blog = array();
$blog['uri'] = (string) $citation->attributes()->uri;
$blog['from'] = "Postgenomic via Plos";
$blog['pubDate'] = date('c', strtotime($citation->pubdate[0]));
$blog['title'] = (string) $citation->title[0];
$blog['blogName'] = (string) $citation->blog_name[0];
$blogs[] = $blog;
}
}
$researchBlogsBlogs = $xml->xpath("//source[@source='Research Blogging']/citations/citation");
if ($researchBlogsBlogs) {
foreach ($researchBlogsBlogs as $citation) {
$blog = array();
$blog['uri'] = (string) $citation->attributes()->uri;
$blog['from'] = "Research Blogging via Plos";
$blog['pubDate'] = date('c', strtotime($citation->details[0]->attributes()->receiveddate));
$blog['title'] = (string) $citation->details[0]->attributes()->title;
$blog['blogName'] = (string) $citation->details[0]->attributes()->name;
$blogs[] = $blog;
}
}
return $blogs ? $this->escArray($blogs) : false;
}
示例9: set_messages
/**
* Retrieve the messages and set the cookies
*
* @return void
*/
protected function set_messages()
{
if (!isset($_COOKIE['messages'][$this->language]) || $this->config['cookie'] == false) {
$xml = file_get_contents("{$this->config['path']}{$this->language}.xml");
if (!($xml = new SimpleXmlElement($xml))) {
throw new Exception('Cannot recover language file');
}
foreach ($xml->xpath('//message') as $msg) {
$this->messages[(string) $msg->attributes()->id[0]] = (string) $msg;
if ($this->config['cookie'] == true) {
setcookie("messages[{$this->language}][{$msg->attributes()->id[0]}]", (string) $msg, time() + 60 * 60 * 24 * 30);
}
}
} else {
foreach ($_COOKIE['messages'][$this->language] as $k => $v) {
$this->messages[$k] = $v;
}
}
}
示例10: getClassDefinitions
/**
* Gets all classes and interfaces from the file and puts them in an easy
* to use array.
*
* @param SimpleXmlElement $xml
* @return void
*/
protected function getClassDefinitions(SimpleXmlElement $xml)
{
foreach ($xml->xpath('file/class|file/interface') as $class) {
$className = (string) $class->full_name;
$className = ltrim($className, '\\');
$fileName = str_replace('\\', '-', $className) . '.md';
$implements = array();
if (isset($class->implements)) {
foreach ($class->implements as $interface) {
$implements[] = ltrim((string) $interface, '\\');
}
}
$extends = array();
if (isset($class->extends)) {
foreach ($class->extends as $parent) {
$extends[] = ltrim((string) $parent, '\\');
}
}
$classNames[$className] = array('fileName' => $fileName, 'className' => $className, 'shortClass' => (string) $class->name, 'namespace' => (string) $class['namespace'], 'description' => (string) $class->docblock->description, 'longDescription' => (string) $class->docblock->{"long-description"}, 'implements' => $implements, 'extends' => $extends, 'isClass' => $class->getName() === 'class', 'isInterface' => $class->getName() === 'interface', 'abstract' => (string) $class['abstract'] == 'true', 'deprecated' => count($class->xpath('docblock/tag[@name="deprecated"]')) > 0, 'methods' => $this->parseMethods($class), 'properties' => $this->parseProperties($class), 'constants' => $this->parseConstants($class));
}
$this->classDefinitions = $classNames;
}
示例11: xpath
/**
*
* @param SimpleXmlElement $dom
* @param type $xpath
* @param type $method
* @return SimpleXmlElement
*/
function xpath($dom, $xpath, $method = 1)
{
if ($dom instanceof SimpleXMLElement == false) {
switch ($method) {
case XPATH_STRING:
return '';
case XPATH_ARRAY:
return array();
case XPATH_DOM:
return null;
}
}
$r = $dom->xpath($xpath);
switch ($method) {
case XPATH_ARRAY:
return $r;
case XPATH_DOM:
return $r[0];
case XPATH_STRING:
default:
return count($r) ? (string) $r[0] : null;
}
}
示例12: generateFiles
/**
* Generate a list of files from the package.xml
* @return Generator
*/
private function generateFiles()
{
/* hook */
$temp = tmpfile();
fprintf($temp, "<?php\nreturn new %s(__DIR__);\n", get_class($this));
rewind($temp);
(yield "pharext_package.php" => $temp);
/* deps */
$dependencies = $this->sxe->xpath("/pecl:package/pecl:dependencies/pecl:required/pecl:package");
foreach ($dependencies as $key => $dep) {
if ($glob = glob("{$this->path}/{$dep->name}-*.ext.phar*")) {
usort($glob, function ($a, $b) {
return version_compare(substr($a, strpos(".ext.phar", $a)), substr($b, strpos(".ext.phar", $b)));
});
(yield end($glob));
}
}
/* files */
(yield realpath($this->file));
foreach ($this->sxe->xpath("//pecl:file") as $file) {
(yield realpath($this->path . "/" . $this->dirOf($file) . "/" . $file["name"]));
}
}
示例13: testSelectsCorrectDate
public function testSelectsCorrectDate()
{
$this->dateTimeForm->setDateTime('2000-01-01 01:01:01');
$xml = '<minacl>' . $this->dateTimeForm->__toString() . '</minacl>';
/*
* replace the with nothing otherwise it'll cause an error
* (as we are not including the html entity definitions here)
*/
$xml = str_replace(' ', '', $xml);
$dom = new SimpleXmlElement($xml);
$year = $dom->xpath("//select[@id='test_year']/option[@selected='selected']");
$this->assertEquals('2000', (string) $year[0], 'Selected year is 2000');
$month = $dom->xpath("//select[@id='test_month']/option[@selected='selected']");
$this->assertEquals('January', (string) $month[0], 'Selected month is January');
$day = $dom->xpath("//select[@id='test_day']/option[@selected='selected']");
$this->assertEquals('01', (string) $day[0], 'Selected day is 01');
$hour = $dom->xpath("//select[@id='test_hour']/option[@selected='selected']");
$this->assertEquals('01', (string) $hour[0], 'Selected hour is 01');
$minutes = $dom->xpath("//select[@id='test_minute']/option[@selected='selected']");
$this->assertEquals('01', (string) $minutes[0], 'Selected minutes is 01');
$seconds = $dom->xpath("//select[@id='test_second']/option[@selected='selected']");
$this->assertEquals('01', (string) $seconds[0], 'Selected seconds is 01');
}
示例14: getLanguage
public static function getLanguage($xml, $langCode, $fallbackCode = 'en-gb', $opts = array())
{
if (!isset($xml)) {
return '';
}
$retVal = $xml;
if (strpos($xml, '<languages>') !== false) {
if ($fallbackCode == null || !isset($fallbackCode)) {
$fallbackCode = self::$defaultFallbackCode;
}
$langCode = strtolower($langCode);
$fallbackCode = strtolower($fallbackCode);
if (strlen($langCode) > 2) {
$langCode = substr($langCode, 0, 2);
}
if (strlen($fallbackCode) > 2) {
$fallbackCode = substr($fallbackCode, 0, 2);
}
$xml = self::stripInvalidXml($xml);
$xdoc = new SimpleXmlElement($xml);
$item = $xdoc->xpath("language [@code='" . $langCode . "']");
$result = '';
$retVal = '';
if (!empty($item)) {
$result = (string) $item[0];
}
if ($result == '' && $fallbackCode != '') {
$item = $xdoc->xpath("language [@code='" . $fallbackCode . "']");
}
if (!empty($item)) {
$retVal = (string) $item[0];
}
//$retVal = (string)$item[0];
}
if (isset($opts) && count($opts) > 0) {
foreach ($opts as $key => $opt) {
switch (strtolower($key)) {
case 'ln2br':
$retVal = nl2br($retVal, true);
break;
case 'htmlencode':
$retVal = htmlentities($retVal, ENT_COMPAT);
break;
case 'striptags':
$retVal = strip_tags($retVal, "<br><br/>");
break;
case 'nomore1br':
$retVal = preg_replace("/\n+/", "\n", $retVal);
break;
default:
break;
}
}
}
return $retVal;
}
示例15: handleForm
/**
* Handle form input related to backdropPost(). Ensure that the specified fields
* exist and attempt to create POST data in the correct manner for the particular
* field type.
*
* @param $post
* Reference to array of post values.
* @param $edit
* Reference to array of edit values to be checked against the form.
* @param $submit
* Form submit button value.
* @param SimpleXmlElement $form
* A SimpleXmlElement containing the form.
* @return
* Submit value matches a valid submit input in the form.
*/
protected function handleForm(&$post, &$edit, &$upload, $submit, $form)
{
// Retrieve the form elements.
$elements = $form->xpath('.//input[not(@disabled)]|.//textarea[not(@disabled)]|.//select[not(@disabled)]');
$submit_matches = FALSE;
foreach ($elements as $element) {
// SimpleXML objects need string casting all the time.
$name = (string) $element['name'];
// This can either be the type of <input> or the name of the tag itself
// for <select> or <textarea>.
$type = isset($element['type']) ? (string) $element['type'] : $element->getName();
$value = isset($element['value']) ? (string) $element['value'] : '';
$done = FALSE;
if (isset($edit[$name])) {
switch ($type) {
case 'color':
case 'email':
case 'hidden':
case 'number':
case 'range':
case 'text':
case 'tel':
case 'textarea':
case 'url':
case 'password':
case 'search':
$post[$name] = $edit[$name];
unset($edit[$name]);
break;
case 'radio':
if ($edit[$name] == $value) {
$post[$name] = $edit[$name];
unset($edit[$name]);
}
break;
case 'checkbox':
// To prevent checkbox from being checked.pass in a FALSE,
// otherwise the checkbox will be set to its value regardless
// of $edit.
if ($edit[$name] === FALSE) {
unset($edit[$name]);
continue 2;
} else {
unset($edit[$name]);
$post[$name] = $value;
}
break;
case 'select':
$new_value = $edit[$name];
$options = $this->getAllOptions($element);
if (is_array($new_value)) {
// Multiple select box.
if (!empty($new_value)) {
$index = 0;
$key = preg_replace('/\\[\\]$/', '', $name);
foreach ($options as $option) {
$option_value = (string) $option['value'];
if (in_array($option_value, $new_value)) {
$post[$key . '[' . $index++ . ']'] = $option_value;
$done = TRUE;
unset($edit[$name]);
}
}
} else {
// No options selected: do not include any POST data for the
// element.
$done = TRUE;
unset($edit[$name]);
}
} else {
// Single select box.
foreach ($options as $option) {
if ($new_value == $option['value']) {
$post[$name] = $new_value;
unset($edit[$name]);
$done = TRUE;
break;
}
}
}
break;
case 'file':
$upload[$name] = $edit[$name];
unset($edit[$name]);
//.........这里部分代码省略.........