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


PHP DOMDocument::setAttribute方法代码示例

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


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

示例1: __call

 /**
  * Generic call-Method instead of numerous setter methods
  * @param             string              $method                       The name of the method, which is called for the Item-Object
  * @param             array               $args                         The arguments with them the method is called - minOccurance = 0, maxOccurance = 2:
  *                                                                      The first argument must be a positive integer (will be used as a index)
  *                                                                      The second argument is optional and would be used as value for the DOMNode
  */
 public function __call($method, $args)
 {
     if (substr($method, 0, 3) == "set" && $args[0] != '') {
         $attributeName = substr($method, 3);
         $value = $args[0];
         if (preg_match('/[0-9]+,[0-9]+/', $value, $match)) {
             $value = str_replace(',', '.', $match[0]);
         }
         if (preg_match('/[0-9]+.[0-9]+/', $value, $match) && $value == $match[0] && $attributeName != 'shippingCosts' && (is_int(strpos($attributeName, 'price')) || is_int(strpos($attributeName, 'Price')) || is_int(strpos($attributeName, 'Tax')) || is_int(strpos($attributeName, 'cost')) || is_int(strpos($attributeName, 'Cost')))) {
             $value = number_format(floatval($match[0]), 2, '.', '');
         }
         $this->node->setAttribute($attributeName, $value);
     } elseif ($args[0] != '') {
         if (sizeof($args) > 2) {
             die("It is not allowed to set more than 2 arguments for the node '{$method}'!");
         }
         if (!is_int($args[0]) || $args[0] < 1) {
             die("The first argument for the node '{$method}' must be whole number, bigger than 0!");
         }
         $name = $method . '[' . $args[0] . ']';
         $xpath = new \DOMXPath($this->doc);
         $qry = $xpath->query($name, $this->node);
         if ($qry->length > 0) {
             return new ORDER($this->doc, $qry->item(0));
         } else {
             if (array_key_exists(1, $args)) {
                 $value = $args[1];
                 if (preg_match('/[0-9]+,[0-9]+/', $value, $match)) {
                     $value = str_replace(',', '.', $match[0]);
                 }
                 if (preg_match('/[0-9]+.[0-9]+/', $value, $match) && $value == $match[0] && $name != 'shippingCosts' && (is_int(strpos($name, 'price')) || is_int(strpos($name, 'Price')) || is_int(strpos($name, 'Tax')) || is_int(strpos($name, 'cost')) || is_int(strpos($name, 'Cost')))) {
                     $value = number_format(floatval($match[0]), 2, '.', '');
                 }
                 $node = $this->doc->createElement($method, $value);
             } else {
                 $node = $this->doc->createElement($method);
             }
             $node = $this->node->appendChild($node);
             return new ORDER($this->doc, $node);
         }
     }
 }
开发者ID:stalinko,项目名称:laravel-mpay24,代码行数:49,代码来源:orderXML.php

示例2: catch

        $Registry = RegistryModuleFactory::GetInstance()->GetRegistryByExtension($_SESSION["TLD"]);
        $registry_exists = true;
    } catch (Exception $e) {
        $registry_exists = false;
    }
}
if ($_SESSION["selected_domain"] && $registry_exists) {
    $node = new DOMDocument("1.0", "UTF-8");
    $node->loadXML(@file_get_contents(dirname(__FILE__) . "/../../../etc/client_domain_nav.xml"));
    $XMLNav->AddNode($node->documentElement, $XMLNav->XML->documentElement);
    $XPath = new DOMXPath($XMLNav->XML);
    $entries = $XPath->query('//node[@type = "tasks"]', $XMLNav->XML->documentElement);
    if ($entries && $entries->item(0)) {
        foreach ($entries as $node) {
            if ($node instanceof DOMElement) {
                $node->setAttribute("title", sprintf(_("Tasks for %s"), "{$_SESSION['domain']}.{$_SESSION['TLD']}"));
            }
        }
    }
    $entries = $XPath->query('//item[@type != ""]', $XMLNav->XML->documentElement);
    if ($entries && $entries->item(0)) {
        foreach ($entries as $node) {
            if ($node instanceof DOMElement) {
                $exists = false;
                $type = $node->getAttribute("type");
                foreach (UI::GetContactsListForSmarty($Registry->Manifest->GetSectionConfig()) as $ck => $cv) {
                    if ($cv["type"] == $type) {
                        $exists = true;
                    }
                }
                if (!$exists) {
开发者ID:rchicoria,项目名称:epp-drs,代码行数:31,代码来源:navigation.inc.php

示例3: createTypeElement

 /**
  * @param \DOMDocument $document
  * @param \DOMElement|\DOMDocument|null $parentElement
  * @param string $type
  *
  * @return \DOMElement
  */
 private static function createTypeElement(\DOMDocument $document, $parentElement = null, $type)
 {
     if ($parentElement->parentNode === null) {
         $typeElement = $document->createElementNS('https://github.com/RhubarbPHP/Rhubarb/blob/master/docs/simple-xml-transcoder.md', self::XMLNS . ':' . $type);
         $parentElement->appendChild($typeElement);
     } else {
         $parentElement->setAttribute(self::XMLNS . ':' . self::ATTR_TYPE, $type);
         $typeElement = $parentElement;
     }
     return $typeElement;
 }
开发者ID:rhubarbphp,项目名称:rhubarb,代码行数:18,代码来源:SimpleXmlTranscoder.php


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