本文整理汇总了PHP中DOMDocument类的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument类的具体用法?PHP DOMDocument怎么用?PHP DOMDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DOMDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decodeGz64
function decodeGz64()
{
$contentNodes = $this->xpath->query("//content");
foreach ($contentNodes as $contentNode) {
if ($contentNode->getAttribute("contentType") == "application/x-gzip" && $contentNode->getAttribute('contentTransferEncoding') == "base64") {
$contentDOM = new \DOMDocument();
$contentDOM->loadXML(gzdecode(base64_decode($contentNode->nodeValue)));
$xmlns = "http://schemas.ogf.org/nml/2013/05/base#";
$tagName = "Topology";
foreach ($contentDOM->getElementsByTagNameNS($xmlns, $tagName) as $netNode) {
$node = $this->xml->importNode($netNode, true);
$contentNode->nodeValue = "";
$contentNode->removeAttribute("contentType");
$contentNode->removeAttribute('contentTransferEncoding');
$contentNode->appendChild($node);
}
$xmlns = "http://schemas.ogf.org/nsi/2014/02/discovery/nsa";
$tagName = "nsa";
foreach ($contentDOM->getElementsByTagNameNS($xmlns, $tagName) as $nsaNode) {
$node = $this->xml->importNode($nsaNode, true);
$contentNode->nodeValue = "";
$contentNode->removeAttribute("contentType");
$contentNode->removeAttribute('contentTransferEncoding');
$contentNode->appendChild($node);
}
}
}
}
示例2: modify
function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
{
$dom = $namedParameters['dom'];
if ( $dom instanceof eZContentObjectAttribute )
{
$this->ObjectAttributeId = $dom->attribute( 'id' );
$content = $dom->attribute( 'content' );
$xmlData = $content->attribute( 'xml_data' );
$domTree = new DOMDocument( '1.0', 'utf-8' );
$domTree->preserveWhiteSpace = false;
$success = $domTree->loadXML( $xmlData );
$tocText = '';
if ( $success )
{
$this->HeaderCounter = array();
$this->LastHeaderLevel = 0;
$rootNode = $domTree->documentElement;
$tocText .= $this->handleSection( $rootNode );
while ( $this->LastHeaderLevel > 0 )
{
$tocText .= "</li>\n</ul>\n";
$this->LastHeaderLevel--;
}
}
}
$operatorValue = $tocText;
}
示例3: testConvertWrongConfiguration
/**
* Testing converting not valid cron configuration, expect to get exception
*
* @expectedException \InvalidArgumentException
*/
public function testConvertWrongConfiguration()
{
$xmlFile = __DIR__ . '/_files/sales_invalid.xml';
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
$this->_converter->convert($dom);
}
示例4: serialize
/**
* (non-PHPdoc)
* @see lib/Faett/Channel/Serializer/Interfaces/Faett_Channel_Serializer_Interfaces_Serializer#serialize()
*/
public function serialize()
{
try {
// initialize a new DOM document
$doc = new DOMDocument('1.0', 'UTF-8');
// create new namespaced root element
$a = $doc->createElementNS($this->_namespace, 'a');
// add the schema to the root element
$a->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', 'http://pear.php.net/dtd/rest.allcategories http://pear.php.net/dtd/rest.allcategories.xsd');
// create an element for the channel's name
$ch = $doc->createElement('ch');
$ch->nodeValue = Mage::helper('channel')->getChannelName();
// append the element with the channel's name to the root element
$a->appendChild($ch);
// load the product's attributes
$attributes = $this->_category->getSelectOptions();
// iterate over the channel's categories
foreach ($attributes as $attribute) {
$c = $doc->createElement('c');
$c->setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '/channel/index/c/' . $attribute . '/info.xml');
$c->nodeValue = $attribute;
// append the XLink to the root element
$a->appendChild($c);
}
// append the root element to the DOM tree
$doc->appendChild($a);
// return the XML document
return $doc->saveXML();
} catch (Exception $e) {
return $e->getMessage();
}
}
示例5: getMessage
/**
*
* @return string
*/
public function getMessage()
{
if (empty($this->_jobTraining)) {
return '';
}
$this->_dom = new DOMDocument();
$classMessage = 'alert ';
$divFluid = $this->_dom->createElement('div');
$divMessage = $this->_dom->createElement('div');
$divFluid->setAttribute('class', 'row-fluid');
if ($this->_jobTraining->status != 1) {
$classMessage .= 'alert-error';
$iconClass = 'icon-remove-sign';
$alertText = ' Atensaun ';
$message = ' Job Training ' . ($this->_jobTraining->status == 2 ? 'Kansela' : 'Taka') . ' tiha ona, La bele halo Atualizasaun.';
} else {
$iconClass = 'icon-ok-sign';
$classMessage .= 'alert-success';
$alertText = '';
$message = ' Job Training Loke, então bele halo Atualizasaun.';
}
$divMessage->setAttribute('class', $classMessage);
$strong = $this->_dom->createElement('strong');
$i = $this->_dom->createElement('i');
$i->setAttribute('class', $iconClass);
$strong->appendChild($i);
$strong->appendChild($this->_dom->createTextNode($alertText));
$divMessage->appendChild($strong);
$divMessage->appendChild($this->_dom->createTextNode($message));
$divFluid->appendChild($divMessage);
$this->_dom->appendChild($divFluid);
return $this->_dom->saveHTML();
}
示例6: loadDOC
function loadDOC($html)
{
$doc = new DOMDocument('1.0', 'UTF8');
$doc->formatOutput = false;
@$doc->loadHTML($html, LIBXML_COMPACT | LIBXML_NOERROR | LIBXML_NOBLANKS | LIBXML_NOWARNING | LIBXML_ERR_NONE | LIBXML_NOXMLDECL | LIBXML_HTML_NODEFDTD | LIBXML_PARSEHUGE);
return $doc;
}
示例7: _testXPath
function _testXPath($xpath_expression)
{
if (!class_exists('DOMDocument') || !class_exists('DOMXPath')) {
if (function_exists('domxml_open_mem')) {
$dom = domxml_open_mem($this->_response);
if (!$dom) {
$this->fail('Error parsing doc');
return false;
}
var_dump($dom);
$xpath = $dom->xpath_init();
var_dump($xpath);
$ctx = $dom->xpath_new_context();
var_dump($xpath_expression);
$result = $ctx->xpath_eval($xpath_expression);
var_dump($result);
$return = new stdClass();
$return->length = count($result->nodeset);
return $return;
}
$this->fail('No xpath support built in');
return false;
} else {
if (extension_loaded('domxml')) {
$this->fail('Please disable the domxml extension. Only php5 builtin domxml is supported');
return false;
}
}
$dom = new DOMDocument();
$dom->loadHtml($this->_response);
$xpath = new DOMXPath($dom);
$node = $xpath->query($xpath_expression);
return $node;
}
示例8: saveConfig
/**
* Save the setup data
* @param array $dbconfig
* @param array $preferences
*
* <?xml version="1.0" encoding="UTF-8"?>
<shineisp>
<config>
<database>
<hostname>localhost</hostname>
<db>shineisp</db>
<username>shineisp</username>
<password>shineisp2013</password>
</database>
</config>
</shineisp>
*/
public static function saveConfig($dbconfig, $version = null)
{
try {
$xml = new SimpleXMLElement('<shineisp></shineisp>');
if (!empty($version)) {
$xml->addAttribute('version', $version);
}
$xml->addAttribute('setupdate', date('Ymdhis'));
$config = $xml->addChild('config');
// Database Configuration
$database = $config->addChild('database');
$database->addChild('hostname', $dbconfig->hostname);
$database->addChild('username', $dbconfig->username);
$database->addChild('password', $dbconfig->password);
$database->addChild('database', $dbconfig->database);
// Get the xml string
$xmlstring = $xml->asXML();
// Prettify and save the xml configuration
$dom = new DOMDocument();
$dom->loadXML($xmlstring);
$dom->formatOutput = true;
$dom->saveXML();
// Save the config xml file
if (@$dom->save(APPLICATION_PATH . "/configs/config.xml")) {
Shineisp_Commons_Utilities::log("Update ShineISP config xml file");
return true;
} else {
throw new Exception("Error on saving the xml file in " . APPLICATION_PATH . "/configs/config.xml <br/>Please check the folder permissions");
}
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
return false;
}
示例9: excludeContentByClass
/**
* Exclude some html parts by class inside content wrapped with TYPO3SEARCH_begin and TYPO3SEARCH_end
* markers.
*
* @param string $indexableContent HTML markup
* @return string HTML
*/
public function excludeContentByClass($indexableContent)
{
if (empty(trim($indexableContent))) {
return html_entity_decode($indexableContent);
}
$excludeClasses = $this->getConfiguration()->getIndexQueuePagesExcludeContentByClassArray();
if (count($excludeClasses) === 0) {
return html_entity_decode($indexableContent);
}
$isInContent = Util::containsOneOfTheStrings($indexableContent, $excludeClasses);
if (!$isInContent) {
return html_entity_decode($indexableContent);
}
$doc = new \DOMDocument('1.0', 'UTF-8');
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . $indexableContent);
$xpath = new \DOMXPath($doc);
foreach ($excludeClasses as $excludePart) {
$elements = $xpath->query("//*[contains(@class,'" . $excludePart . "')]");
if (count($elements) == 0) {
continue;
}
foreach ($elements as $element) {
$element->parentNode->removeChild($element);
}
}
$html = $doc->saveHTML($doc->documentElement->parentNode);
// remove XML-Preamble, newlines and doctype
$html = preg_replace('/(<\\?xml[^>]+\\?>|\\r?\\n|<!DOCTYPE.+?>)/imS', '', $html);
$html = str_replace(array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $html);
return $html;
}
示例10: parseResults
private function parseResults($html)
{
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
$elements = $xpath->query('//*[@id="middenkolom"]/div/table/tbody/tr');
$results = array();
if (!is_null($elements)) {
foreach ($elements as $element) {
// Get image
foreach ($xpath->query('td[1]/a/img', $element) as $image) {
$imageUrl = 'http://www.nedgame.nl' . $image->getAttribute('src');
}
// Get link & title
foreach ($xpath->query('td[2]/a', $element) as $link) {
$url = $link->getAttribute('href');
$title = $link->nodeValue;
}
// Get price
foreach ($xpath->query('td[3]/div/div[4]', $element) as $prices) {
preg_match('/([0-9,\\-]+)/', $prices->nodeValue, $matches);
$price = $matches[0];
}
// Get platform
foreach ($xpath->query('td[2]/span', $element) as $details) {
preg_match('/Platform: (.*)Type:/', $details->nodeValue, $matches);
$platform = $matches[1];
}
$results[] = array('title' => $title, 'url' => $url, 'img' => $imageUrl, 'platform' => $platform, 'price' => $price);
}
return $results;
}
}
示例11: launch
/**
* Process parameters and display the page.
*
* @return void
* @access public
*/
public function launch()
{
global $interface;
// Retrieve the record from the index
if (!($record = $this->db->getRecord($_GET['id']))) {
PEAR_Singleton::raiseError(new PEAR_Error('Record Does Not Exist'));
}
// Send basic information to the template.
$interface->setPageTitle(isset($record['heading']) ? $record['heading'] : 'Heading unavailable.');
$interface->assign('record', $record);
// Load MARC data
require_once ROOT_DIR . '/sys/MarcLoader.php';
$marcRecord = MarcLoader::loadMarcRecordFromRecord($record);
if (!$marcRecord) {
PEAR_Singleton::raiseError(new PEAR_Error('Cannot Process MARC Record'));
}
$xml = trim($marcRecord->toXML());
// Transform MARCXML
$style = new DOMDocument();
$style->load('services/Record/xsl/record-marc.xsl');
$xsl = new XSLTProcessor();
$xsl->importStyleSheet($style);
$doc = new DOMDocument();
if ($doc->loadXML($xml)) {
$html = $xsl->transformToXML($doc);
$interface->assign('details', $html);
}
// Assign the ID of the last search so the user can return to it.
$interface->assign('lastsearch', isset($_SESSION['lastSearchURL']) ? $_SESSION['lastSearchURL'] : false);
// Display Page
$interface->setTemplate('record.tpl');
$interface->display('layout.tpl');
}
示例12: show
function show()
{
$channel_id = $this->input['channel_id'];
if (!$channel_id) {
$this->errorOutput('该频道不存在或者已被删除');
}
$dates = $this->input['dates'];
if (!$dates) {
$this->errorOutput('这一天不存在节目');
}
$sql = "select * from " . DB_PREFIX . "program where channel_id=" . $channel_id . " AND dates='" . $dates . "' ORDER BY start_time ASC ";
$q = $this->db->query($sql);
header('Content-Type: text/xml; charset=UTF-8');
$dom = new DOMDocument('1.0', 'utf-8');
$program = $dom->createElement('program');
while ($row = $this->db->fetch_array($q)) {
$item = $dom->createElement('item');
$item->setAttribute('name', urldecode($row['theme']));
$item->setAttribute('startTime', $row['start_time'] * 1000);
$item->setAttribute('duration', $row['toff'] * 1000);
$program->appendChild($item);
}
$dom->appendChild($program);
echo $dom->saveXml();
}
示例13: invokeGetOrder
function invokeGetOrder(MarketplaceWebServiceOrders_Interface $service, $request)
{
try {
$response = $service->GetOrder($request);
$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$data = $dom->saveXML();
$xml = simplexml_load_string($data);
if (empty($xml->GetOrderResult->Orders)) {
return false;
} else {
//$xml->GetOrderResult->Orders
return true;
}
} catch (MarketplaceWebServiceOrders_Exception $ex) {
$message = 'MWS Order API : Caught Exception : ' . $ex->getMessage() . "\n";
$message .= "Response Status Code: " . $ex->getStatusCode() . "\n";
$message .= "Error Code: " . $ex->getErrorCode() . "\n";
$message .= "Error Type: " . $ex->getErrorType() . "\n";
$param['message'] = $message;
$this->generate_log($param);
}
}
示例14: googleArray
/**
* Returns array, containing detailed results for any Google search.
*
* @access private
* @param string $query String, containing the search query.
* @param string $tld String, containing the desired Google top level domain.
* @return array Returns array, containing the keys 'URL', 'Title' and 'Description'.
*/
public static function googleArray($query)
{
$result = array();
$pages = 1;
$delay = 0;
for ($start = 0; $start < $pages; $start++) {
$url = 'http://www.google.' . GOOGLE_TLD . '/custom?q=' . $query . '&filter=0' . '&num=100' . ($start == 0 ? '' : '&start=' . $start . '00');
$str = SEOstats::cURL($url);
if (preg_match("#answer=86640#i", $str)) {
$e = 'Please read: http://www.google.com/support/websearch/' . 'bin/answer.py?&answer=86640&hl=en';
throw new SEOstatsException($e);
} else {
$html = new DOMDocument();
@$html->loadHtml($str);
$xpath = new DOMXPath($html);
$links = $xpath->query("//div[@class='g']//a");
$descs = $xpath->query("//td[@class='j']//div[@class='std']");
$i = 0;
foreach ($links as $link) {
if (!preg_match('#cache#si', $link->textContent) && !preg_match('#similar#si', $link->textContent)) {
$result[] = array('url' => $link->getAttribute('href'), 'title' => utf8_decode($link->textContent), 'descr' => utf8_decode($descs->item($i)->textContent));
$i++;
}
}
if (preg_match('#<div id="nn"><\\/div>#i', $str) || preg_match('#<div id=nn><\\/div>#i', $str)) {
$pages += 1;
$delay += 200000;
usleep($delay);
} else {
$pages -= 1;
}
}
}
return $result;
}
示例15: process
/**
* Обрабатывает данные.
* @param string $data XML-строка
*/
public function process($data)
{
$errorHandler = new \WebConstructionSet\Xml\LibxmlErrorHandler();
$xml = new \DOMDocument();
if (!$xml->loadXML($data)) {
throw new \ErrorException('Document parse failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
}
$xsl = new \DOMDocument();
if ($this->xslString) {
if (!$xsl->loadXML($this->xslString)) {
throw new \ErrorException('XSL stylesheet load/parse failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
}
} else {
$xslPath = $this->getXslStylesheetPath($xml);
if (!$xslPath) {
throw new \ErrorException('XSL stylesheet path is not found.', null, null, __FILE__, __LINE__);
}
if (!$xsl->load($xslPath)) {
throw new \ErrorException('XSL stylesheet load/parse failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
}
}
$xslt = new \XSLTProcessor();
if (!$xslt->importStylesheet($xsl)) {
throw new \ErrorException('Import XSL stylesheet failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
}
$this->resultDoc = $xslt->transformToDoc($xml);
if (!$this->resultDoc) {
throw new \ErrorException('XSLT transform failed. ' . $errorHandler->getErrorString(), null, null, __FILE__, __LINE__);
}
// no return
}