本文整理汇总了PHP中DOMNode::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMNode::setAttribute方法的具体用法?PHP DOMNode::setAttribute怎么用?PHP DOMNode::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMNode
的用法示例。
在下文中一共展示了DOMNode::setAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcessXML
/**
* @param \DOMNode $node
*/
protected function postProcessXML($node)
{
// дата релиза
if (!is_null($this->release)) {
$release = date('d-m-Y', strtotime($this->release . ' 00:00:00'));
$node->setAttribute('release', $release);
$xDate = explode('-', $release);
$fullDate = $xDate[0] . ' ' . \Difra\Locales::getInstance()->getXPath('portfolio/months/m_' . $xDate[1]) . ' ' . $xDate[2];
$node->setAttribute('fullDate', $fullDate);
}
// авторы
if (!is_null($this->authors)) {
$authorsArray = unserialize($this->authors);
if (!empty($authorsArray)) {
foreach ($authorsArray as $k => $data) {
if (isset($data['role'])) {
$roleNode = $node->appendChild($node->ownerDocument->createElement('role'));
$roleNode->setAttribute('name', $data['role']);
if (isset($data['contibutors']) && is_array($data['contibutors'])) {
foreach ($data['contibutors'] as $cName) {
$cNode = $roleNode->appendChild($node->ownerDocument->createElement('contibutor'));
$cNode->setAttribute('name', $cName);
}
}
}
}
}
}
}
示例2: sanitize
public function sanitize(\DOMNode $node)
{
if ($this->haveToTrim() && $node->hasAttribute($this->name)) {
$node->setAttribute($this->name, trim($node->getAttribute($this->name)));
}
if ($this->repair && !$node->hasAttribute($this->name)) {
$node->setAttribute($this->name, $this->repairValue);
}
}
示例3: apply
/**
* Adds class="external" & rel="nofollow" to external links.
*
* @param \DOMNode $node Link
* @param \Title $title
*/
public function apply(\DOMNode $node, \Title $title)
{
if (!$node instanceof \DOMElement) {
return;
}
$node->setAttribute('class', 'external');
global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
if ($wgNoFollowLinks && !wfMatchesDomainList($node->getAttribute('href'), $wgNoFollowDomainExceptions)) {
$node->setAttribute('rel', 'nofollow');
}
}
示例4: getEditXML
/**
* @param \DOMNode|\DOMElement $node
* @param int $menuId
*/
private function getEditXML($node, $menuId)
{
$menu = \Difra\Plugins\CMS\Menu::get($menuId);
$node->setAttribute('depth', $menu->getDepth());
$parentsNode = $node->appendChild($this->xml->createElement('parents'));
\Difra\Plugins\CMS::getInstance()->getMenuItemsXML($parentsNode, $menu->getId());
}
示例5: visitArray
public function visitArray($data, Type $type, Context $context)
{
if ($this->nodeStack->count() === 1 && $this->document->documentElement === null) {
$this->createRootNode();
}
/** @var PropertyMetadata $metadata */
$nodeName = 'entry';
if (($metadata = $context->getMetadataStack()->getCurrent()) && !empty($metadata->xmlEntryName)) {
$nodeName = $metadata->xmlEntryName;
}
$attributeName = null !== $metadata ? $metadata->xmlKeyAttribute : null;
$namespace = null !== $metadata ? $metadata->xmlEntryNamespace : null;
/** @var \DOMNode[] $nodes */
$nodes = [];
$elementType = $this->getElementType($type);
foreach ($data as $k => $v) {
$elementName = null !== $metadata && $metadata->xmlKeyValuePairs && $this->isElementNameValid($k) ? (string) $k : $nodeName;
$this->currentNodes = $this->createElement($namespace, $elementName);
$context->accept($v, $elementType);
if (null !== $attributeName) {
$this->currentNodes->setAttribute($attributeName, (string) $k);
}
$nodes[] = $this->currentNodes;
}
return $this->currentNodes = $nodes;
}
示例6: getStateXML
/**
* Get some configuration variables as XML node attributes
* @param \DOMElement|\DOMNode $node
*/
public static function getStateXML($node)
{
$config = self::getState();
foreach ($config as $k => $v) {
$node->setAttribute($k, $v);
}
}
示例7: rtrim
static function append_style(DOMNode $node, $new_style)
{
$style = rtrim($node->getAttribute(self::$_style_attr), ";");
$style .= $new_style;
$style = ltrim($style, ";");
$node->setAttribute(self::$_style_attr, $style);
}
示例8: attr
public function attr($a_name, $a_value = null)
{
if (is_null($a_value)) {
return $this->m_node->getAttribute($a_name);
}
$this->m_node->setAttribute($a_name, $a_value);
}
示例9: handleBody
/**
* Handle body.
*
* @param type $def
* @return none
*
* @throws Exception
*/
protected function handleBody($def)
{
$def = IdmlPxeExportParentMap::parsePixieDef($def);
if (strtolower($def['tagName']) != 'body') {
throw Exception('handling body that is not body. How did you get here?');
}
$this->pxeBody->setAttribute('class', $def['class']);
}
示例10: setError
/**
* Set error response.
*
* @param \WP_Error|null $error Response error.
* @param string $tag Response XML tag (defaults to `authenticationFailure`).
*
* @uses \WP_Error
* @uses \do_action()
*/
public function setError(\WP_Error $error = null, $tag = 'authenticationFailure')
{
/**
* Fires if the CAS server has to return an XML error.
*
* @param WP_Error $error WordPress error to return as XML.
*/
\do_action('cas_server_error', $error);
$message = __('Unknown error', 'wp-cas-server');
$code = GeneralException::ERROR_INTERNAL_ERROR;
if (!empty($error)) {
$code = $error->get_error_code();
$message = $error->get_error_message($code);
}
$this->response = $this->createElement($tag, $message);
$this->response->setAttribute('code', $code);
}
示例11: addBooleanAttributes
/**
* Like addAttributes, but runs each value through normalization.
* @see XmlPutter::addAttributes
*
* @param array $attributes
*/
public function addBooleanAttributes($attributes = array())
{
foreach ($attributes as $key => $value) {
if ($value === null) {
continue;
}
$this->current->setAttribute($key, TypeNormalization::normalizeBooleanToString($value));
}
}
示例12:
function set_id($id)
{
$this->_id = $id;
// We can only set attributes of DOMElement objects (nodeType == 1).
// Since these are the only objects that we can assign CSS rules to,
// this shortcoming is okay.
if ($this->_node->nodeType == 1) {
$this->_node->setAttribute("frame_id", $id);
}
}
示例13: __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);
}
}
}
示例14: attr
public function attr($a_name, $a_value = null)
{
if (func_num_args() == 0) {
return $this->m_node->getAttribute($a_name);
}
if (func_num_args() > 1) {
$this->m_node->setAttribute($a_name, $a_value);
}
if (func_num_args() == 1) {
$this->m_node->getAttribute($a_name);
}
}
示例15: __set
/**
* Vraci attributy
* @param string $name
* @throws LBoxExceptionConfig
*/
public function __set($name = "", $value = "")
{
if (strlen($name) < 1) {
throw new LBoxExceptionConfig(LBoxExceptionConfig::MSG_PARAM_STRING_NOTNULL, LBoxExceptionConfig::CODE_BAD_PARAM);
}
if ($value === NULL) {
$this->node->removeAttribute($name);
} else {
if (!$this->node->setAttribute($name, $value)) {
throw new LBoxExceptionConfig(LBoxExceptionConfig::MSG_ATTRIBUTE_CANNOT_CHANGE, LBoxExceptionConfig::CODE_ATTRIBUTE_CANNOT_CHANGE);
}
}
}