本文整理汇总了PHP中DOMXpath类的典型用法代码示例。如果您正苦于以下问题:PHP DOMXpath类的具体用法?PHP DOMXpath怎么用?PHP DOMXpath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DOMXpath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
/**
* {@inheritdoc}
*/
public function apply(base $databox, Application $app)
{
$structure = $databox->get_structure();
$DOM = new DOMDocument();
$DOM->loadXML($structure);
$xpath = new DOMXpath($DOM);
foreach ($xpath->query('/record/subdefs/subdefgroup[@name="video"]/subdef[@name="preview"]/acodec') as $node) {
$node->nodeValue = 'libvo_aacenc';
}
foreach ($xpath->query('/record/subdefs/subdefgroup[@name="video"]/subdef[@name="preview"]/vcodec') as $node) {
$node->nodeValue = 'libx264';
}
$databox->saveStructure($DOM);
$subdefgroups = $databox->get_subdef_structure();
foreach ($subdefgroups as $groupname => $subdefs) {
foreach ($subdefs as $name => $subdef) {
$this->addScreenDeviceOption($subdefgroups, $subdef, $groupname);
if (in_array($name, ['preview', 'thumbnail'])) {
if ($name == 'thumbnail' || $subdef->getSubdefType()->getType() != \Alchemy\Phrasea\Media\Subdef\Subdef::TYPE_VIDEO) {
$this->addMobileSubdefImage($subdefgroups, $subdef, $groupname);
} else {
$this->addMobileSubdefVideo($subdefgroups, $subdef, $groupname);
}
}
if ($subdef->getSubdefType()->getType() != \Alchemy\Phrasea\Media\Subdef\Subdef::TYPE_VIDEO) {
continue;
}
$this->addHtml5Video($subdefgroups, $subdef, $groupname);
}
}
return true;
}
示例2: hasSignificantWhitespace
/**
* Returns if significant whitespaces occur in the paragraph.
*
* This method checks if the paragraph $element contains significant
* whitespaces in form of <text:s/> or <text:tab/> elements.
*
* @param DOMElement $element
* @return bool
*/
protected function hasSignificantWhitespace(DOMElement $element)
{
$xpath = new DOMXpath($element->ownerDocument);
$xpath->registerNamespace('text', ezcDocumentOdt::NS_ODT_TEXT);
$whitespaces = $xpath->evaluate('.//text:s|.//text:tab|.//text:line-break', $element);
return $whitespaces instanceof DOMNodeList && $whitespaces->length > 0;
}
示例3: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$metadata = $manager->getClassMetaData(get_class(new Operator()));
$metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
$i = 1;
$file = dirname(__FILE__) . '/../../operators.xml';
$doc = new \DOMDocument();
$doc->load($file);
$xpath = new \DOMXpath($doc);
$elements = $xpath->query('/operators/operator');
if (!is_null($elements)) {
/** @var $element DOMNode */
foreach ($elements as $element) {
$operator = new Operator();
$operator->setId($i);
$operator->setType($this->getTypeForString($element->getAttribute('type')));
$operator->setOperator($element->getAttribute('operator'));
$operator->setInputType($element->getAttribute('inputType'));
// translations
$translations = $xpath->query('translations/translation', $element);
$this->processTranslations($manager, $operator, $translations);
// values
$values = $xpath->query('values/value', $element);
$this->processValues($manager, $xpath, $operator, $values);
$manager->persist($operator);
++$i;
}
}
$manager->flush();
}
示例4: rerender
/**
*
*/
public function rerender()
{
$cssFileContent = '';
$components = $this->uiComposer->getUiComponents();
//Get all CSS file content
foreach ($components as $component) {
//TODO: check renderresult instead of component type
if ($component instanceof HtmlWidget) {
$cssFileContent .= $component->getRenderResult()->cssFileContent;
}
}
if (trim($cssFileContent)) {
// build file
$cssFileContent = $this->minify($cssFileContent);
$httpFileNamePath = '/generated/' . md5($cssFileContent) . '.css';
$fileNamePath = 'public' . $httpFileNamePath;
if (!file_exists($fileNamePath)) {
file_put_contents($fileNamePath, $cssFileContent);
}
// get $doc and add the href
$doc = $this->uiComposer->getDoc();
//TODO: use composer xpath?
$xPath = new \DOMXpath($this->uiComposer->getDoc());
$linkElement = $xPath->query('//link[@id="css-file"]');
//TODO url function missing
$linkElement->item(0)->setAttribute('href', FC::assetLink($httpFileNamePath));
}
$this->needsRerender = false;
}
示例5: HTMLtoLunchArray
protected function HTMLtoLunchArray($html)
{
$doc = new DOMDocument();
@$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
$dElements = array(0 => array(1), 1 => array(2), 2 => array(3), 3 => array(4), 4 => array(5));
$arr = array();
foreach ($dElements as $dId => $dArr) {
$dayMenu = '';
foreach ($dArr as $dRow) {
$element = $xpath->query('/html/body/div[2]/div[2]/article/div/div/p[' . $dRow . ']');
foreach ($element as $e) {
$dayMenuExploded = explode(PHP_EOL, $e->nodeValue);
$foodArray = array();
foreach ($dayMenuExploded as $foods) {
$foods = parent::cleanStr($foods);
if (!empty($foods)) {
$foodArray[] = preg_replace('/([\\t0-9, ]+$)/', '', $foods);
}
}
$dayMenu = implode(' / ', $foodArray);
}
}
$weekDay = parent::weekNumToText($dId);
$arr[$weekDay] = parent::fixSpaces(preg_replace('/[0-9, ]+$/', '', $dayMenu));
}
if (!empty($arr)) {
return $arr;
}
return false;
}
示例6: populate_resource
function populate_resource($id, $overrideExportable = false)
{
//local SOLR index for fast searching
$ci =& get_instance();
$ci->load->library('solr');
$ci->solr->clearOpt('fq');
$ci->solr->setOpt('fq', '+id:' . $id);
$this->overrideExportable = $overrideExportable;
$result = $ci->solr->executeSearch(true);
if (sizeof($result['response']['docs']) == 1) {
$this->index = $result['response']['docs'][0];
}
//local XML resource
$xml = $this->ro->getSimpleXML();
$xml = addXMLDeclarationUTF8($xml->registryObject ? $xml->registryObject->asXML() : $xml->asXML());
$xml = simplexml_load_string($xml);
$xml = simplexml_load_string(addXMLDeclarationUTF8($xml->asXML()));
if ($xml) {
$this->xml = $xml;
$rifDom = new DOMDocument();
$rifDom->loadXML($this->ro->getRif());
$gXPath = new DOMXpath($rifDom);
$gXPath->registerNamespace('ro', 'http://ands.org.au/standards/rif-cs/registryObjects');
$this->gXPath = $gXPath;
}
}
示例7: HTMLtoLunchArray
/**
* @param string $html HTML document
* @return boolean|array
*/
public function HTMLtoLunchArray($html)
{
$doc = new DOMDocument();
@$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
$dElements = array(0 => array(2, 3, 4));
$arr = array();
foreach ($dElements as $dId => $dArr) {
$dayMenu = array();
foreach ($dArr as $dRow) {
$element = $xpath->query('/html/body/div[2]/div/div/div/div/div[' . $dRow . ']/div[1]');
foreach ($element as $e) {
$dish = ucfirst(strtolower(parent::cleanStr(utf8_decode(parent::fixSpaces(trim($e->nodeValue))))));
$dish = preg_replace('/\\([a-z, ]+\\)/e', 'strtoupper("$0")', $dish);
$dayMenu[] = $dish;
}
}
$weekDay = parent::today();
$arr[$weekDay] = implode(' / ', $dayMenu);
}
if (!empty($arr)) {
return $arr;
}
return false;
}
示例8: buildMeta
/**
* Retreives a list of tags for a given resource that are marked
* "Sujet principal".
*
* With the "non_principal_fallback" option set to TRUE, in the
* event that there are no "sujet principal" tags, all the tags will
* be used instead.
*
* (There should probably be a parameter for the string "Sujet
* principal".)
*
* @param $url Optional. Defaults to current page.
* @param $non_principal_fallback boolean Get all tags if there are NO "sujet principal".
* @returns folksoPageDataMeta object
*/
public function buildMeta($url = NULL, $max_tags = 0, $non_principal_fallback = NULL)
{
$mt = new folksoPageDataMeta();
$this->getData($url);
/** could set a maximum here, but instead we can
set that at display time, since we might be
reusing data.
NB: if $url is NULL, getData() will use
$this->url anyway.
**/
if ($this->is_valid()) {
$xpath = new DOMXpath($this->xml_DOM());
// reusing existing DOM, maybe
//$tag_princ is a DOMNodelist object
$tag_princ = $xpath->query('//taglist/tag[metatag="Sujet principal"]');
// 'Sujet principal' only
if ($tag_princ->length > 0) {
foreach ($tag_princ as $element) {
$tagname = $element->getElementsByTagName('display');
$mt->add_principal_keyword($tagname->item(0)->textContent);
}
}
// All tags, when no 'sujet principal' is found.
$all_tags = $xpath->query('//taglist/tag');
if ($all_tags->length > 0) {
foreach ($all_tags as $element) {
$tagname = $element->getElementsByTagName('display');
$mt->add_all_tags($tagname->item(0)->textContent);
}
}
$this->mt = $mt;
return $mt;
}
}
示例9: process
function process(&$article)
{
$owner_uid = $article["owner_uid"];
if (strpos($article["link"], "threewordphrase.com") !== FALSE) {
if (strpos($article["plugin_data"], "af_comics,{$owner_uid}:") === FALSE) {
$doc = new DOMDocument();
@$doc->loadHTML(fetch_file_contents($article["link"]));
$basenode = false;
if ($doc) {
$xpath = new DOMXpath($doc);
$basenode = $xpath->query("//td/center/img")->item(0);
if ($basenode) {
$article["content"] = $doc->saveXML($basenode);
$article["plugin_data"] = "af_comics,{$owner_uid}:" . $article["plugin_data"];
}
}
} else {
if (isset($article["stored"]["content"])) {
$article["content"] = $article["stored"]["content"];
}
}
return true;
}
return false;
}
示例10: get_image
function get_image($game, $name, $width, $height)
{
$url = 'http://steamcommunity.com/market/listings/' . $game . '/' . rawurlencode($name) . '/render?start=0&count=1¤cy=1&format=json';
$response = get_page_html($url);
$jobject = json_decode($response);
if (!isset($jobject)) {
return null;
}
// Get the HTML render
$render_html = $jobject->results_html;
// Parse the html
$dom = new DOMDocument();
$dom->loadHTML($render_html);
$xpath = new DOMXpath($dom);
// Get the image
$img = $xpath->query('//img[@class="market_listing_item_img"]')->item(0);
if (!isset($img)) {
return null;
}
// Get image src
$imgurl = $img->getAttribute('src');
// Remove the pre-set size
$imgurl = substr($imgurl, 0, strrpos($imgurl, '/'));
// Replace with our size
$imgurl .= '/' . $width . 'fx' . $height . 'f';
return $imgurl;
}
示例11: provideCategoryNameNodes
/**
* Provide DOMNodeLists of CategoryLink/Name nodes and a collection of categories.
*
* @return array[]
*/
public function provideCategoryNameNodes()
{
$doc = Mage::helper('eb2ccore')->getNewDomDocument();
$doc->loadXML('
<CategoryLinks>
<CategoryLink import_mode="Update">
<Name>Luma Root</Name>
</CategoryLink>
<CategoryLink import_mode="Update">
<Name>Luma Root-Shoes</Name>
</CategoryLink>
<CategoryLink import_mode="Update">
<Name>Luma Root-Shoes-Boots</Name>
</CategoryLink>
<!-- The item should end up in Luma Root/Outerwear/Jackets, but not Luma Root/Outerwear -->
<CategoryLink import_mode="Update">
<Name>Luma Root-Outerwear-Jackets</Name>
</CategoryLink>
</CategoryLinks>
');
$xp = new DOMXpath($doc);
$nodes = $xp->query('/CategoryLinks/CategoryLink[@import_mode!="Delete"]/Name');
$catCol = $this->getResourceModelMockBuilder('catalog/category_collection')->setMethods(array('addAttributeToSelect', 'getColumnValues', 'getAllIds'))->getMock();
$catCol->expects($this->any())->method('addAttributeToSelect')->with($this->identicalTo(array('name', 'path', 'id')))->will($this->returnSelf());
$ids = array(0, 1, 2, 3, 30, 31);
$names = array('Root Catalog', 'Luma Root', 'Shoes', 'Boots', 'Outerwear', 'Jackets');
$paths = array('0', '0/1', '0/1/2', '0/1/2/3', '0/1/30', '0/1/30/31');
$catCol->expects($this->any())->method('getColumnValues')->will($this->returnValueMap(array(array('name', $names), array('path', $paths))));
$catCol->expects($this->any())->method('getAllIds')->will($this->returnValue($ids));
return array(array($nodes, $catCol));
}
示例12: count_quotations
function count_quotations($html)
{
/* Count the number of quotations using the 'cite' tag
* (Used to determine if URL should be submitted to Neotext)
*
* Credit: http://htmlparsing.com/php.html
*/
$quotations_count = 0;
# Parse the HTML
# The @ before the method call suppresses any warnings that
# loadHTML might throw because of invalid HTML in the page.
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
# Iterate over all the <blockquote> and <q> tags
$quotations = $xpath->query('//blockquote | //q');
//foreach($dom->getElementsByTagName('blockquote') as $quote) {
foreach ($quotations as $quote) {
$cite_url = $quote->getAttribute('cite');
// If URL in valid form:
if (!filter_var($cite_url, FILTER_VALIDATE_URL) === false) {
$quotations_count = $quotations_count + 1;
}
}
return $quotations_count;
}
示例13: testOff
function testOff()
{
$doc = $this->process_post("[bibshow file=custom://data show_links=0][bibcite key=test]", ShowLinks::$data);
$xpath = new DOMXpath($doc);
$href = $xpath->evaluate("//a[@class = 'papercite_bibcite']/@href");
$this->assertEquals(0, $href->length, "There were {$href->length} links detected - expected none");
}
示例14: LINKS
public static function LINKS($url)
{
$content = file_get_contents($url);
$doc = new \DOMDocument();
$doc->loadHTML($content);
// \bloc\application::instance()->log($doc);
$xpath = new \DOMXpath($doc);
$handle = curl_init("https://validator.nu/?level=error&doc={$url}&out=json");
curl_setopt_array($handle, [CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT']]);
$report = json_decode(curl_exec($handle));
$number_of_errors = count($report->messages);
$files = [['name' => 'index.html', 'content' => $content, 'type' => 'lang-html', 'url' => $url, 'report' => ['count' => count($report->messages), 'errors' => (new \bloc\types\Dictionary($report->messages))->map(function ($item) {
return ['line' => $item->lastLine ?? 1, 'message' => $item->message];
})]], ['name' => 'README', 'content' => null, 'type' => 'plain-text', 'url' => base64_encode($url . '/readme.txt')]];
foreach ($xpath->query("//script[@src and not(contains(@src, 'http'))]") as $file) {
$src = $file->getAttribute('src');
$files[] = ['url' => base64_encode($url . '/' . $src), 'name' => substr($src, strrpos($src, '/') + 1), 'content' => null, 'type' => 'lang-js'];
}
foreach ($xpath->query("//link[not(contains(@href, 'http')) and contains(@href, '.css')]") as $file) {
$src = $file->getAttribute('href');
$uri = $url . '/' . $src;
$code = substr(get_headers($uri)[0], 9, 3);
if ($code < 400) {
$report = json_decode(file_get_contents("https://jigsaw.w3.org/css-validator/validator?output=json&warning=0&profile=css3&uri=" . $uri));
$count = $report->cssvalidation->result->errorcount;
} else {
$report = 'not-found';
$count = "fix";
}
$files[] = ['url' => base64_encode($uri), 'name' => substr($src, strrpos($src, '/') + 1), 'content' => null, 'type' => 'lang-css', 'report' => ['count' => $count, 'errors' => (new \bloc\types\Dictionary($report->cssvalidation->errors ?? []))->map(function ($item) {
return ['line' => $item->line, 'message' => $item->message];
})]];
}
return $files;
}
示例15: indexAction
public function indexAction()
{
SxCms_Acl::requireAcl('ad', 'ad.edit');
$filename = APPLICATION_PATH . '/var/ads.xml';
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadXml(file_get_contents($filename));
$dom->formatOutput = true;
$xpath = new DOMXpath($dom);
$xml = simplexml_import_dom($dom);
if ($this->getRequest()->isPost()) {
$ads = $this->_getParam('ad');
foreach ($ads as $key => $value) {
$nodeList = $xpath->query("//zone[id='{$key}']/content");
if ($nodeList->length) {
$cdata = $dom->createCDATASection(stripslashes($value));
$content = $dom->createElement('content');
$content->appendChild($cdata);
$nodeList->item(0)->parentNode->replaceChild($content, $nodeList->item(0));
}
}
$dom->save($filename);
$flashMessenger = $this->_helper->getHelper('FlashMessenger');
$flashMessenger->addMessage('Advertentie werd succesvol aangepast');
}
$this->view->ads = $xml;
}