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


PHP DOMDocument::getElementsByTagname方法代码示例

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


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

示例1: toGeoJSON

function toGeoJSON($resultFileURI)
{
    $doc = new DOMDocument();
    /*
     * Load error => return an empty GeoJSON
     */
    if (@$doc->load($resultFileURI) === false) {
        $geojson = array('type' => 'FeatureCollection', 'features' => array());
        return json_encode($geojson);
    }
    $entries = $doc->getElementsByTagname('entry');
    /*
     * No SearchResult => return an empty GeoJSON
     */
    if ($entries->item(0) == null) {
        /*
         * GeoJSON
         */
        $geojson = array('type' => 'FeatureCollection', 'features' => array());
        return json_encode($geojson);
    }
    /*
     * GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'features' => array());
    foreach ($entries as $entry) {
        /**
         * Add feature
         */
        $feature = array('type' => 'Feature', 'geometry' => pointToGeoJSONGeometry($entry->getElementsByTagname('lng')->item(0)->nodeValue, $entry->getElementsByTagname('lat')->item(0)->nodeValue), 'properties' => array('name' => $entry->getElementsByTagname('title')->item(0)->nodeValue, 'description' => $entry->getElementsByTagname('summary')->item(0)->nodeValue, 'url' => $entry->getElementsByTagname('wikipediaUrl')->item(0)->nodeValue, 'img_url' => $entry->getElementsByTagname('thumbnailImg')->item(0)->nodeValue));
        // Add feature array to feature collection array
        array_push($geojson['features'], $feature);
    }
    return json_encode($geojson);
}
开发者ID:ssunkari,项目名称:mapshup,代码行数:35,代码来源:search.php

示例2: openGame

 public function openGame($idx)
 {
     $file = $this->games[$idx]['name'];
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = true;
     $doc->formatOutput = true;
     // modify state
     $libxml_previous_state = libxml_use_internal_errors(true);
     // parse
     $doc->loadHTMLFile("Games/" . $file);
     // Usuwanie scriptow - bład z tagamiw scripcie
     $domNodeList = $doc->getElementsByTagname('script');
     $domElemsToRemove = array();
     foreach ($domNodeList as $domElement) {
         $domElemsToRemove[] = $domElement;
     }
     foreach ($domElemsToRemove as $domElement) {
         $domElement->parentNode->removeChild($domElement);
     }
     $xpath = new DomXpath($doc);
     // traverse all results
     foreach ($xpath->query('//div[@tiddler]') as $tid) {
         if ($tid->getAttribute('tiddler') != 'checkvars') {
             $this->tiddlers[$tid->getAttribute('tiddler')] = $tid->nodeValue;
         }
     }
     // handle errors
     libxml_clear_errors();
     // restore
     libxml_use_internal_errors($libxml_previous_state);
 }
开发者ID:Largin,项目名称:TwineDoodler,代码行数:31,代码来源:games.php

示例3: outputToGeoJSON

function outputToGeoJSON($theData)
{
    $doc = new DOMDocument();
    $doc->loadXML($theData);
    /*
     * Get the SearchResults object
     */
    $searchResults = $doc->getElementsByTagname('SearchResults');
    /*
     * No SearchResult => return an error
     */
    if ($searchResults->item(0) == null) {
        /*
         * Send an error
         */
        $geojson = array('error' => array('message' => urldecode($theData)));
        return json_encode($geojson);
    }
    /*
     * GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'totalResults' => $searchResults->item(0)->getAttribute('numberOfRecordsMatched'), 'features' => array());
    $dataObjects = $doc->getElementsByTagname('Record');
    $array = array("\r\n", "\n\r", "\n", "\r");
    foreach ($dataObjects as $dataObject) {
        /*
         * Footprint is processed from LowerCorner / UpperCorner properties
         * Order is Longitude Latitude
         * If no footprint is found, skip the data
         */
        if ($dataObject->getElementsByTagName('LowerCorner')->length > 0 && $dataObject->getElementsByTagName('UpperCorner')->length > 0) {
            $lowerCorner = explode(' ', $dataObject->getElementsByTagName('LowerCorner')->item(0)->nodeValue);
            $upperCorner = explode(' ', $dataObject->getElementsByTagName('UpperCorner')->item(0)->nodeValue);
            /*
             * Bug from INSPIRE catalog ?
             * Be sure that lowerCorner is lower right and not lower left
             */
            $lonmin = min(floatval($lowerCorner[0]), floatval($upperCorner[0]));
            $lonmax = max(floatval($lowerCorner[0]), floatval($upperCorner[0]));
            $latmin = min(floatval($lowerCorner[1]), floatval($upperCorner[1]));
            $latmax = max(floatval($lowerCorner[1]), floatval($upperCorner[1]));
        } else {
            /**
             * Footprint is null => skip data
             */
            continue;
        }
        /** Skip whole earth dataset */
        if ($lonmin == -180 && $lonmax == 180 && $latmin == -90 && $latmax == 90) {
            continue;
        }
        /**
         * Add feature
         */
        $feature = array('type' => 'Feature', 'geometry' => bboxToGeoJSONGeometry($lonmin, $latmin, $lonmax, $latmax), 'properties' => array('identifier' => $dataObject->getElementsByTagName('identifier')->length > 0 ? $dataObject->getElementsByTagName('identifier')->item(0)->nodeValue : "", 'modified' => $dataObject->getElementsByTagName('modified')->length > 0 ? $dataObject->getElementsByTagName('modified')->item(0)->nodeValue : "", 'title' => $dataObject->getElementsByTagName('title')->length > 0 ? $dataObject->getElementsByTagName('title')->item(0)->nodeValue : "", 'type' => $dataObject->getElementsByTagName('type')->length > 0 ? $dataObject->getElementsByTagName('type')->item(0)->nodeValue : "", 'subject' => $dataObject->getElementsByTagName('subject')->length > 0 ? $dataObject->getElementsByTagName('subject')->item(0)->nodeValue : "", 'format' => $dataObject->getElementsByTagName('format')->length > 0 ? $dataObject->getElementsByTagName('format')->item(0)->nodeValue : "", 'creator' => $dataObject->getElementsByTagName('creator')->length > 0 ? $dataObject->getElementsByTagName('creator')->item(0)->nodeValue : "", 'publisher' => $dataObject->getElementsByTagName('publisher')->length > 0 ? $dataObject->getElementsByTagName('publisher')->item(0)->nodeValue : "", 'abstract' => str_replace($array, "", $dataObject->getElementsByTagName('abstract')->length > 0 ? $dataObject->getElementsByTagName('abstract')->item(0)->nodeValue : ""), 'language' => $dataObject->getElementsByTagName('language')->length > 0 ? $dataObject->getElementsByTagName('language')->item(0)->nodeValue : "", 'thumbnail' => "", 'quicklook' => ""));
        // Add feature array to feature collection array
        array_push($geojson['features'], $feature);
    }
    return json_encode($geojson);
}
开发者ID:ssunkari,项目名称:mapshup,代码行数:60,代码来源:local_CSWISOCatalogProxy.php

示例4: parse

 /**
  * Parsing the XML Doumenttype for elements named "field"!
  * Allocates the member variables currentElement, formElements.
  * Parses "field" for existing attributes, subfields and subelements like "default" and "required-if-fulltext".
  * At the end each found element is transformed to Zend_Element and stored in array.
  */
 public function parse()
 {
     //parse root node for tags named 'field'
     foreach ($this->dom->getElementsByTagname('field') as $field) {
         $currentElement = new Publish_Model_FormElement($this->form);
         $currentElement->setAdditionalFields($this->additionalFields);
         $this->_parseAttributes($field, $currentElement);
         $this->_parseSubFields($field, $currentElement);
         $this->_parseDefaultEntry($currentElement, $field);
         $this->_parseRequiredIfFulltext($field, $currentElement);
         $currentElement->setPostValues($this->postValues);
         $group = $currentElement->initGroup();
         $this->formElements[] = $group;
         if (!isset($group)) {
             $element = $currentElement->transform();
             $this->formElements[] = $element;
         }
     }
 }
开发者ID:alexukua,项目名称:opus4,代码行数:25,代码来源:DocumenttypeParser.php

示例5: atlas_preprocess_menu_tree

function atlas_preprocess_menu_tree(&$variables)
{
    $tree = new DOMDocument();
    @$tree->loadHTML($variables['tree']);
    $links = $tree->getElementsByTagname('li');
    $parent = '';
    foreach ($links as $link) {
        $parent = $link->getAttribute('data-menu-parent');
        break;
    }
    $variables['menu_parent'] = $parent;
}
开发者ID:kveldalf,项目名称:prometheus,代码行数:12,代码来源:template.php

示例6: getTags

 public static function getTags(&$article, $tags)
 {
     $dom = new DOMDocument();
     $dom->preserveWhiteSpace = false;
     @$dom->loadHTML(strip_tags($article->summary . " " . $article->body, implode("", $tags)));
     $text = array();
     foreach ($tags as $tag) {
         $content = $dom->getElementsByTagname(str_replace(array('<', '>'), '', $tag));
         foreach ($content as $item) {
             $text[] = $item->nodeValue;
         }
     }
     return $text;
 }
开发者ID:bellodox,项目名称:jsolr,代码行数:14,代码来源:Helper.php

示例7: array

 function get_xml_values()
 {
     //echo "In Get_XML_VALUES";
     $url = 'http://api.hotukdeals.com/rest_api/v2/?key=a253c459cfb0f079712de5f2ec54df03&merchant=argos&online_offline=online&order=hot&forum=deals&results_per_page=30';
     $const_string = array('title', 'deal_link', 'deal_image', 'description', 'submit_time', 'temperature', 'price', 'expired');
     $arr = array();
     try {
         $dom = new DOMDocument(1.0);
         $file = file_get_contents($url);
         $dom->loadXML($file);
         //Obtains all the necessary details from Hot UK deals
         $api_response = $dom->getElementsByTagname('api_response');
         //echo ($api_response->item(0)->hasChildNodes());
         if ($api_response->item(0)->hasChildNodes()) {
             $deal_node = $api_response->item(0)->getElementsByTagname('deals')->item(0);
             //echo '\n'.$deal_node->nodeName;
             if ($deal_node->hasChildNodes()) {
                 $count = get_node_count($deal_node);
                 //echo $count;
                 //$incr =0;
                 //echo '<\br>'.$deal_node->childNodes->item(0)->nodeName;
                 foreach ($deal_node->childNodes as $values) {
                     $item_array = array();
                     //deal_node is <deals>
                     //children of deal_node are <api_item>'s
                     foreach ($values->childNodes as $item) {
                         //Loop through each node/element/item in <api_items>
                         for ($i = 0; $i < count($const_string); $i++) {
                             if (strcmp($item->nodeName, $const_string[$i]) == 0) {
                                 if (strcmp($const_string[$i], 'deal_image') == 0) {
                                     $item_array[$const_string[$i]] = $item->nodeValue;
                                     $result = array();
                                     $image_id = preg_match_all("/[\\d-_]+/", $item_array[$const_string[$i]], $result);
                                     //$image_id = preg_match_all("/((?:[Tt]hreads\/)([\w\d-_]+))/", $item_array[$const_string[$i]], $result);
                                     $item_array['link'] = "http://www.hotukdeals.com/visit?m=5&q=" . $result[0][0] . ".jpg";
                                 }
                                 $item_array[$const_string[$i]] = $item->nodeValue;
                                 break;
                             }
                         }
                     }
                     $arr[] = $item_array;
                 }
             }
         }
     } catch (exception $e) {
         echo 'Exception Message: ', $e->getMessage(), '\\n';
     }
     return $arr;
 }
开发者ID:vahizan,项目名称:ArgosTask,代码行数:50,代码来源:api.php

示例8: search

function search($param) {
  $ret=array();
  $search_str=$param['value'];
  $add_param=array();

  $search_str=urlencode($search_str);
  $add_param[]="q=$search_str";

  if($param['shown'])
    $add_param[]="exclude_place_ids={$param['shown']}";

  if($param['viewbox'])
    $add_param[]="viewbox={$param['viewbox']}";

  $add_param[]="format=xml";

  $res=file_get_contents("http://nominatim.openstreetmap.org/search?".
                         implode("&", $add_param));

  $resdom=new DOMDocument();
  $resdom->loadXML($res);

  $obl=$resdom->getElementsByTagname("place");
  for($i=0; $i<$obl->length; $i++) {
    $ob=$obl->item($i);

    $type=$ob->getAttribute("osm_type");
    if($type=="relation")
      $type="rel";
    $id=$ob->getAttribute("osm_id");

    $nominatim_id=$ob->getAttribute("place_id");

    $ret_ob=array(
      'osm_id'   =>"{$type}_{$id}",
      'osm_tags' =>array(),
    );

    $ret_ob['osm_tags']['name']=$ob->getAttribute("display_name");
    $ret_ob['osm_tags']['nominatim_id']=$nominatim_id;
    $ret_ob['osm_tags']['lat']=$ob->getAttribute("lat");
    $ret_ob['osm_tags']['lon']=$ob->getAttribute("lon");

    $ret[]=$ret_ob;
  }

  return $ret;
}
开发者ID:plepe,项目名称:OpenStreetBrowser,代码行数:48,代码来源:code.php

示例9: knacc_get_content_link

/**
 * Get first link from the post content
 */
function knacc_get_content_link()
{
    $dom = new DOMDocument();
    $dom->loadHTML(apply_filters('the_content', get_the_content('')));
    $link = $dom->getElementsByTagname('a');
    if ($link->item(0)) {
        foreach ($link->item(0)->attributes as $attribute) {
            if ($attribute->name == 'href') {
                $link = $attribute->value;
            }
        }
        return $link;
    } else {
        return false;
    }
}
开发者ID:bryanpbaker,项目名称:philgood-theme,代码行数:19,代码来源:helper-functions.php

示例10: _scanComponent

 /**
  * Scan the component directory and get some useful info
  * @return type 
  */
 private function _scanComponent()
 {
     $path = $this->_root . '/component';
     // Find the XML files
     foreach (new DirectoryIterator($path) as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         if (!$fileInfo->isFile()) {
             continue;
         }
         $fname = $fileInfo->getFilename();
         if (substr($fname, -4) != '.xml') {
             continue;
         }
         $xmlDoc = new DOMDocument();
         $xmlDoc->load($path . '/' . $fname, LIBXML_NOBLANKS | LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NONET);
         $rootNodes = $xmlDoc->getElementsByTagname('install');
         $altRootNodes = $xmlDoc->getElementsByTagname('extension');
         if ($altRootNodes->length >= 1) {
             unset($rootNodes);
             $rootNodes = $altRootNodes;
         }
         if ($rootNodes->length < 1) {
             unset($xmlDoc);
             continue;
         }
         $root = $rootNodes->item(0);
         if (!$root->hasAttributes()) {
             unset($xmlDoc);
             continue;
         }
         if ($root->getAttribute('type') != 'component') {
             unset($xmlDoc);
             continue;
         }
         // Get the component name
         $component = strtolower($xmlDoc->getElementsByTagName('name')->item(0)->textContent);
         if (substr($component, 0, 4) != 'com_') {
             $component = 'com_' . $component;
         }
         // Get the <files> tags for front and back-end
         $siteFolder = $path;
         $allFilesTags = $xmlDoc->getElementsByTagName('files');
         $nodePath0 = $allFilesTags->item(0)->getNodePath();
         $nodePath1 = $allFilesTags->item(1)->getNodePath();
         if (in_array($nodePath0, array('/install/files', '/extension/files'))) {
             $siteFilesTag = $allFilesTags->item(0);
             $adminFilesTag = $allFilesTags->item(1);
         } else {
             $siteFilesTag = $allFilesTags->item(1);
             $adminFilesTag = $allFilesTags->item(0);
         }
         // Get the site and admin folders
         if ($siteFilesTag->hasAttribute('folder')) {
             $siteFolder = $path . '/' . $siteFilesTag->getAttribute('folder');
         }
         if ($adminFilesTag->hasAttribute('folder')) {
             $adminFolder = $path . '/' . $adminFilesTag->getAttribute('folder');
         }
         // Get the media folder
         $mediaFolder = null;
         $allMediaTags = $xmlDoc->getElementsByTagName('media');
         if ($allMediaTags->length >= 1) {
             $mediaFolder = $path . '/' . $allMediaTags->item(0)->getAttribute('folder');
         }
         // Do we have a CLI folder
         $cliFolder = $path . '/cli';
         if (!is_dir($cliFolder)) {
             $cliFolder = '';
         }
         // Get the <languages> tags for front and back-end
         $langFolderSite = $path;
         $langFolderAdmin = $path;
         $allLanguagesTags = $xmlDoc->getElementsByTagName('languages');
         $nodePath0 = $allLanguagesTags->item(0)->getNodePath();
         $nodePath1 = $allLanguagesTags->item(1)->getNodePath();
         if (in_array($nodePath0, array('/install/languages', '/extension/languages'))) {
             $siteLanguagesTag = $allLanguagesTags->item(0);
             $adminLanguagesTag = $allLanguagesTags->item(1);
         } else {
             $siteLanguagesTag = $allLanguagesTags->item(1);
             $adminLanguagesTag = $allLanguagesTags->item(0);
         }
         // Get the site and admin language folders
         if ($siteLanguagesTag->hasAttribute('folder')) {
             $langFolderSite = $path . '/' . $siteLanguagesTag->getAttribute('folder');
         }
         if ($adminLanguagesTag->hasAttribute('folder')) {
             $langFolderAdmin = $path . '/' . $adminLanguagesTag->getAttribute('folder');
         }
         // Get the frontend languages
         $langFilesSite = array();
         if ($siteLanguagesTag->hasChildNodes()) {
             foreach ($siteLanguagesTag->childNodes as $langFile) {
                 if (!$langFile instanceof DOMElement) {
//.........这里部分代码省略.........
开发者ID:mybo,项目名称:com_lts,代码行数:101,代码来源:relink.php

示例11: DOMDocument

    echo "\n    Usage : " . $_SERVER['argv'][0] . " path_to_product.xml" . "\n\n";
    exit;
}
/*
 * Input xml product must exist
 */
if (!file_exists($file)) {
    echo "\n    ERROR : " . $file . " does not exists" . "\n\n";
    exit;
}
/*
 * Input xml product descriptor must exist and be a valid XML document
 */
$doc = new DOMDocument();
$doc->load($file);
if ($doc->getElementsByTagname('OTBProduct')->item(0) == NULL) {
    echo "\n    ERROR : " . $file . " is not a valid jeotb product descriptor" . "\n\n";
    exit;
}
/**
 * Database connection
 */
$dbh = pg_connect("host=localhost dbname=jeotb user=otb password=otb00") or die("Database connection error");
/**
 * Insert new entry within logger table
 * and return newly created astext(center) within
 * the $result variable
 */
$fields = "(identifier,acquisition,archive,creation,description,location,metadata,title,type,wms_layer,wms_url,footprint)";
$values = "'" . pg_escape_string($doc->getElementsByTagName('identifier')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('acquisition')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('archive')->item(0)->nodeValue) . "','" . date('Y-m-d\\TH:i:s\\Z', $_SERVER["REQUEST_TIME"]) . "','" . pg_escape_string($doc->getElementsByTagName('description')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('town')->item(0)->nodeValue) . ", " . $doc->getElementsByTagName('country')->item(0)->nodeValue . "','" . pg_escape_string($doc->getElementsByTagName('metadata')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('title')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('type')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('layer')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('url')->item(0)->nodeValue) . "'," . "GeomFromText('" . $doc->getElementsByTagName('footprint')->item(0)->nodeValue . "',4326)";
$query = "INSERT INTO products " . $fields . " VALUES (" . $values . ")";
开发者ID:ssunkari,项目名称:mapshup,代码行数:31,代码来源:ingest.php

示例12: __construct

    if (!empty($_GET['tags'])) {
        $tags = explode(',', $_GET['tags']);
    }
}
error_reporting(E_ALL);
$filename = 'feed.xml';
$dom = new DOMDocument();
$dom->formatOutput = true;
$dom->load($filename);
$xpath = new DOMXPath($dom);
$xpath->registerNamespace('foo', 'http://www.w3.org/2005/Atom');
$entries = $xpath->query('//foo:entry/foo:id[. = "' . $url . '"]/..');
if ($entries->length != 0) {
    die("URL already added.");
}
$dom->getElementsByTagname('updated')->item(0)->nodeValue = date(DateTime::RFC3339);
$first_entry = $dom->getElementsByTagname('entry')->item(0);
$new_entry = new AtomEntryNode($dom);
$new_entry->setFromURL($url);
$dom->documentElement->insertBefore($new_entry->get(), $first_entry);
$dom->save($filename);
const SILENT = 1;
include './create.index.php';
#header('Location: ./');
################
class AtomEntryNode
{
    protected $dom;
    protected $content = null;
    protected $inner;
    public function __construct(DOMDocument $dom)
开发者ID:johannes,项目名称:linkblog,代码行数:31,代码来源:addlink.php

示例13: array_key_prefix

$xml = BASEDIR . 'cache/plugins_xml.php';
if (file_exists($xml)) {
    $xmllastmod = filemtime($xml);
}
$xml = get_fileinfo('http://dragonflycms.org/plugins.php', false, true, $xmllastmod);
if ($xml['modified'] === true) {
    Cache::array_save('xml', 'plugins', $xml);
} else {
    Cache::array_load('xml', 'plugins', true);
}
//$xml['data'] = decode_bb_all($xml['data'], 0 , true);
$xmlDOM = new DOMDocument();
$xmlDOM->preserveWhiteSpace = false;
$xmlDOM->loadXML($xml['data']);
$data = array();
$items = $xmlDOM->getElementsByTagname('item');
foreach ($items as $item) {
    $tmp = array();
    $nodes = $item->childNodes;
    for ($n = 0; $n < $nodes->length; ++$n) {
        $tmp[$nodes->item($n)->nodeName] = $nodes->item($n)->nodeValue;
    }
    $data[$item->parentNode->nodeName][] = $tmp;
}
unset($xmlDOM, $xml, $items, $item, $nodes, $tmp);
function array_key_prefix(&$array, $prefix)
{
    $ret = array();
    foreach ($array as $key => $value) {
        $ret[$prefix . $key] = $value;
        array_shift($array);
开发者ID:cbsistem,项目名称:nexos,代码行数:31,代码来源:plugins.php

示例14: _highlightPhpCode

 /**
  * Highlighter method for PHP source code
  *
  * The source code is highlighted by PHP native method.
  * Afterwords a DOMDocument will be generated with each
  * line in a seperate node.
  *
  * @param String $sourceCode The PHP source code
  *
  * @return DOMDocument
  */
 protected function _highlightPhpCode($sourceCode)
 {
     $code = highlight_string($sourceCode, true);
     $sourceDom = new DOMDocument();
     $sourceDom->loadHTML($code);
     //fetch <code>-><span>->children from php generated html
     $sourceElements = $sourceDom->getElementsByTagname('code')->item(0)->childNodes->item(0)->childNodes;
     //create target dom
     $targetDom = new DOMDocument();
     $targetNode = $targetDom->createElement('ol');
     $targetNode->setAttribute('class', 'code');
     $targetDom->appendChild($targetNode);
     $li = $targetDom->createElement('li');
     $targetNode->appendChild($li);
     // iterate through all <span> elements
     foreach ($sourceElements as $sourceElement) {
         if (!$sourceElement instanceof DOMElement) {
             $span = $targetDom->createElement('span');
             $span->nodeValue = htmlspecialchars($sourceElement->wholeText);
             $li->appendChild($span);
             continue;
         }
         if ('br' === $sourceElement->tagName) {
             // create new li and new line
             $li = $targetDom->createElement('li');
             $targetNode->appendChild($li);
             continue;
         }
         $elementClass = $this->_mapPhpColors($sourceElement->getAttribute('style'));
         foreach ($sourceElement->childNodes as $sourceChildElement) {
             if ($sourceChildElement instanceof DOMElement && 'br' === $sourceChildElement->tagName) {
                 // create new li and new line
                 $li = $targetDom->createElement('li');
                 $targetNode->appendChild($li);
             } else {
                 // apend content to current li element
                 // apend content to urrent li element
                 $span = $targetDom->createElement('span');
                 $span->nodeValue = htmlspecialchars($sourceChildElement->wholeText);
                 $span->setAttribute('class', $elementClass);
                 $li->appendChild($span);
             }
         }
     }
     return $targetDom;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:57,代码来源:ViewReview.php

示例15: DOMDocument

#!/usr/bin/php
<?
$sql=pg_connect("dbname=gis");// user=www password=cityrunner host=localhost");

$dom=new DOMDocument();
$dom->load("/osm/skunkosm/render/overlay_ch.xml");

//$box=array(1823787.494884305,6138504.867525934,1825010.487336868,6139727.859978498);
$box=array(1813797.75987783, 6130153.02441634, 1834395.04941202, 6151816.81425115);

$layers=$dom->getElementsByTagname("Layer");
foreach($layers as $l) {
  print "* Layer, class ".$l->getAttribute("name")."\n";
  $params=$l->getElementsByTagname("Parameter");
  foreach($params as $p) {
    if($p->getAttribute("name")=="table") {
      $time=time();
      $res=pg_query("select * from {$p->firstChild->data} where way && setSRID('BOX3D($box[0] $box[1],$box[2] $box[3])'::box3d,900913)");
      print "Time: ".(time()-$time)."s\n";
      print "Rows: ".pg_num_rows($res)."\n";
    }
  }
}
开发者ID:plepe,项目名称:OpenStreetBrowser,代码行数:23,代码来源:profiler_xml.php


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