本文整理汇总了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);
}
}
}
示例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) {
示例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;
}