本文整理汇总了PHP中DOMElement::removeAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMElement::removeAttribute方法的具体用法?PHP DOMElement::removeAttribute怎么用?PHP DOMElement::removeAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMElement
的用法示例。
在下文中一共展示了DOMElement::removeAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeAttributes
/**
* Removes all attributes from element.
*
* @param DOMElement $element
* The DOMElement to remove attributes from.
*/
protected function removeAttributes($element)
{
$attributes = $element->attributes;
while ($attributes->length) {
$element->removeAttribute($attributes->item(0)->name);
}
}
示例2: postProcessDomNode
protected function postProcessDomNode($field, DOMElement $fieldNode, JForm $form)
{
$fieldNode->setAttribute('validate', 'url');
if (!$fieldNode->getAttribute('relative')) {
$fieldNode->removeAttribute('relative');
}
return parent::postProcessDomNode($field, $fieldNode, $form);
}
示例3: removeAttr
/**
* Usuń atrybut
*
* @param string $name
*
* @return HtmlElement
*
* @throws \UnexpectedValueException
*/
public function removeAttr($name)
{
if (!is_string($name)) {
throw new \UnexpectedValueException('attribute name is not string');
}
$this->element->removeAttribute($name);
return $this;
}
示例4: removeClass
/**
* Removes class $class from $element
*
* @param DOMElement $element
* @param string $class
*/
public function removeClass($element, $class)
{
$newClass = trim(preg_replace("/ *(?:{$class})/i", '', $element->getAttribute('class')));
if ($newClass != '') {
$element->setAttribute('class', $newClass);
} else {
$element->removeAttribute('class');
}
}
示例5: offsetUnset
/**
* Required by the ArrayAccess interface.
*
* @param string $offset
* @return boolean
*/
public function offsetUnset($offset)
{
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);
return $this->_element->removeAttributeNS(Zend_Feed::lookupNamespace($ns), $attr);
} else {
return $this->_element->removeAttribute($offset);
}
}
示例6: offsetUnset
/**
* Required by the ArrayAccess interface.
*
* @internal
*/
public function offsetUnset($offset)
{
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);
$result = $this->_element->removeAttributeNS(Horde_Xml_Element::lookupNamespace($ns), $attr);
} else {
$result = $this->_element->removeAttribute($offset);
}
if ($result) {
$this->_expireCachedChildren();
return true;
} else {
return false;
}
}
示例7: archiveGrp
private function archiveGrp(Application $app, \databox $databox, \DOMDocument $dom, \DOMElement $node, $path, $path_archived, $path_error, array &$nodesToDel, $moveError, $moveArchived, $stat0, $stat1)
{
$xpath = new \DOMXPath($dom);
// grp folders stay in place
$node->setAttribute('keep', '1');
$grpFolder = $node->getAttribute('name');
$groupingFile = $path . '/' . $grpFolder . '/.grouping.xml';
if ($node->getAttribute('grp') == 'tocreate') {
$representationFileName = null;
$representationFileNode = null;
$captionFileName = null;
$captionFileNode = null;
$cid = $node->getAttribute('cid');
$genericdoc = null;
$this->log('debug', sprintf('created story \'%s\'', $path . '/' . $grpFolder));
// if the .grp does not have a representative doc, let's use a generic file
if (!($rep = $node->getAttribute('grp_representation'))) {
try {
$app['filesystem']->copy($app['root.path'] . '/www/assets/common/images/icons/substitution/regroup_doc.png', $genericdoc = $path . '/group.jpg', true);
} catch (IOException $e) {
$this->log('debug', $e->getMessage());
}
$representationFileName = 'group.jpg';
$this->log('debug', ' (no representation file)');
} else {
$dnl = $xpath->query('./file[@name="' . $rep . '"]', $node->parentNode);
$representationFileNode = $dnl->item(0);
$representationFileName = $rep;
$node->removeAttribute('grp_representation');
$this->log('debug', sprintf('representation from \'%s\'', $representationFileName));
}
if (($cap = $node->getAttribute('grp_caption')) != '') {
$dnl = $xpath->query('./file[@name="' . $cap . '"]', $node->parentNode);
$captionFileNode = $dnl->item(0);
$captionFileName = $cap;
$node->removeAttribute('grp_caption');
$this->log('debug', sprintf('caption from \'%s\'', $captionFileName));
}
try {
$collection = \collection::get_from_coll_id($app, $databox, (int) $cid);
if ($captionFileName === null) {
$story = $this->createStory($app, $collection, $path . '/' . $representationFileName, null, $stat0, $stat1);
} else {
$story = $this->createStory($app, $collection, $path . '/' . $representationFileName, $path . '/' . $captionFileName, $stat0, $stat1);
}
$rid = $story->get_record_id();
$this->log('debug', sprintf('story %s created', $rid));
if ($genericdoc) {
try {
$app['filesystem']->remove($genericdoc);
} catch (IOException $e) {
$this->log('debug', $e->getMessage());
}
}
file_put_contents($groupingFile, '<?xml version="1.0" encoding="ISO-8859-1" ?><record grouping="' . $rid . '" />');
$n = $node->appendChild($dom->createElement('file'));
$n->setAttribute('name', '.grouping.xml');
$n->setAttribute('temperature', 'cold');
$n->setAttribute('grp', '1');
$n->setAttribute('match', '*');
if ($moveArchived) {
$this->log('debug', sprintf('copy \'%s\' to \'archived\'', $path . '/' . $grpFolder . '/.grouping.xml'));
try {
$app['filesystem']->mkdir($path_archived . '/' . $grpFolder, 0755);
} catch (IOException $e) {
$this->log('debug', $e->getMessage());
}
try {
$app['filesystem']->copy($path . '/' . $grpFolder . '/.grouping.xml', $path_archived . '/' . $grpFolder . '/.grouping.xml', true);
} catch (IOException $e) {
$this->log('debug', $e->getMessage());
}
}
if ($captionFileNode) {
$captionFileNode->setAttribute('archived', '1');
if ($moveArchived) {
$this->log('debug', sprintf('copy \'%s\' to \'archived\'', $path . '/' . $captionFileName));
try {
$app['filesystem']->mkdir($path_archived, 0755);
} catch (IOException $e) {
$this->log('debug', $e->getMessage());
}
try {
$app['filesystem']->copy($path . '/' . $captionFileName, $path_archived . '/' . $captionFileName, true);
} catch (IOException $e) {
$this->log('debug', $e->getMessage());
}
}
try {
$app['filesystem']->remove($path . '/' . $captionFileName);
} catch (IOException $e) {
$this->log('debug', $e->getMessage());
}
$nodesToDel[] = $captionFileNode;
}
if ($representationFileNode) {
$representationFileNode->setAttribute('archived', '1');
if ($moveArchived) {
$this->log('debug', sprintf('copy \'%s\' to \'archived\'', $path . '/' . $representationFileName));
try {
//.........这里部分代码省略.........
示例8: subcompile
/**
* Renders given DOM element as subtemplate.
*
* @param \DOMElement $domElement DOM element to subrender.
* @param Scope $scope Subtemplate Scope object.
* @return string Rendered HTML.
*/
protected function subcompile(\DOMElement $domElement, $scope)
{
$template = new Template($this->phCompile);
/**
* Remove ng-repeat attribute so we won't fall into infinite loop while parsing.
*/
$domElement->removeAttribute('ng-repeat');
/**
* Tag element with render class, for easy client-side JavaScript manipulation.
*/
Utils::addClass($domElement, $this->phCompile->getConfig('compile.class'));
$template->setHTML($domElement->ownerDocument->saveHTML($domElement));
$template->setScope($scope);
return $template->compile();
}
示例9: ReplaceElementReference
/**
* Replaces an element reference with a copy of the element it references.
* @param DOMElement $elementReference the element reference to replace
* @param DOMXPath $xpath the xpath object representing the DOM
* @access private
*/
private function ReplaceElementReference(DOMElement $elementReference, DOMXPath $xpath)
{
$href = $elementReference->getAttribute('href');
if (version_compare(PHP_VERSION, '5.2.2', '>=') && version_compare(PHP_VERSION, '5.2.4', '<')) {
// These versions have a bug where href is generated without the # symbol.
$href = '#' . $href;
}
$id = substr($href, 1);
$referencedElements = $xpath->query('//*[@id="' . $id . '"]');
if ($referencedElements->length > 0) {
$referencedElement = $referencedElements->item(0);
for ($i = 0; $i < $referencedElement->childNodes->length; $i++) {
$childNode = $referencedElement->childNodes->item($i);
$elementReference->appendChild($childNode->cloneNode(true));
}
$elementReference->removeAttribute('href');
}
}
示例10: cleanAttributes
/**
* Clean all atttributes but allowed
* @param \DOMElement|\DOMNode $node
* @param array $attributes
*/
private function cleanAttributes(&$node, $attributes = [])
{
if (($node instanceof \DOMElement or $node instanceof \DOMNode) and $node->attributes->length) {
$delAttr = [];
foreach ($node->attributes as $attr) {
if (isset($attributes[$attr->name])) {
$filter = $attributes[$attr->name];
$node->setAttribute($attr->name, $this->{$filter}($attr->value));
} elseif (isset($this->allowedAttrsForAll[$attr->name])) {
$filter = $this->allowedAttrsForAll[$attr->name];
$node->setAttribute($attr->name, $this->{$filter}($attr->value));
} else {
$delAttr[] = $attr->name;
}
}
foreach ($delAttr as $da) {
$node->removeAttribute($da);
}
}
}
示例11: ReplaceElementReference
/**
* Replaces an element reference with a copy of the element it references.
*
* @param \DOMElement $elementReference the element reference to replace
* @param \DOMXPath $xpath the xpath object representing the DOM
*/
private function ReplaceElementReference(\DOMElement $elementReference, \DOMXPath $xpath)
{
$href = $elementReference->getAttribute('href');
$id = substr($href, 1);
$referencedElements = $xpath->query('//*[@id="' . $id . '"]');
if ($referencedElements->length > 0) {
$referencedElement = $referencedElements->item(0);
for ($i = 0; $i < $referencedElement->childNodes->length; $i++) {
$childNode = $referencedElement->childNodes->item($i);
$elementReference->appendChild($childNode->cloneNode(true));
}
$elementReference->removeAttribute('href');
}
}
示例12: publishHandlerEmbed
/**
* publishHandlerEmbed (Publish handler, pass 2 after schema validation)
* Publish handler for embed element, convert id to [object|node]_id parameter,
* fixes align=middle value (if embed was image) and tries to map css to attributes
*
* @param DOMElement $element
* @param array $param parameters for xml element
* @return null|array changes structure if it contains 'result' key
*/
function publishHandlerEmbed($element, &$params)
{
$ID = $element->getAttribute('id');
if ($ID) {
$objectID = false;
$element->removeAttribute('id');
if (strpos($ID, 'eZObject_') !== false) {
$objectID = substr($ID, strpos($ID, '_') + 1);
$element->setAttribute('object_id', $objectID);
$object = eZContentObject::fetch($objectID);
if (!$object) {
if (!in_array($objectID, $this->deletedEmbeddedObjectIDArray)) {
$this->deletedEmbeddedObjectIDArray[] = $objectID;
}
} else {
if ($object->attribute('status') == eZContentObject::STATUS_ARCHIVED) {
$this->thrashedEmbeddedObjectIDArray[] = $objectID;
}
}
} else {
if (strpos($ID, 'eZNode_') !== false) {
$nodeID = substr($ID, strpos($ID, '_') + 1);
$element->setAttribute('node_id', $nodeID);
$node = eZContentObjectTreeNode::fetch($nodeID);
if ($node) {
$objectID = $node->attribute('contentobject_id');
} else {
if (!in_array($nodeID, $this->deletedEmbeddedNodeIDArray)) {
$this->deletedEmbeddedNodeIDArray[] = $nodeID;
}
}
}
}
if ($objectID && !in_array($objectID, $this->embeddedObjectIDArray)) {
$this->embeddedObjectIDArray[] = $objectID;
}
}
$align = $element->getAttribute('align');
if ($align && $align === 'middle') {
$element->setAttribute('align', 'center');
}
return null;
}
示例13: parseRoute
/**
* Parses a route and adds it to the RouteCollection.
*
* @param RouteCollection $collection RouteCollection instance
* @param \DOMElement $node Element to parse that represents a Route
* @param string $path Full path of the XML file being processed
*
* @throws \InvalidArgumentException When the XML is invalid
*/
protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
{
if ('' === ($id = $node->getAttribute('id')) || !$node->hasAttribute('pattern') && !$node->hasAttribute('path')) {
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "path" attribute.', $path));
}
if ($node->hasAttribute('pattern')) {
if ($node->hasAttribute('path')) {
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
}
@trigger_error(sprintf('The "pattern" option in file "%s" is deprecated since version 2.2 and will be removed in 3.0. Use the "path" option in the route definition instead.', $path), E_USER_DEPRECATED);
$node->setAttribute('path', $node->getAttribute('pattern'));
$node->removeAttribute('pattern');
}
$schemes = preg_split('/[\\s,\\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY);
$methods = preg_split('/[\\s,\\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY);
list($defaults, $requirements, $options, $condition) = $this->parseConfigs($node, $path);
if (isset($requirements['_method'])) {
if (0 === count($methods)) {
$methods = explode('|', $requirements['_method']);
}
unset($requirements['_method']);
@trigger_error(sprintf('The "_method" requirement of route "%s" in file "%s" is deprecated since version 2.2 and will be removed in 3.0. Use the "methods" attribute instead.', $id, $path), E_USER_DEPRECATED);
}
if (isset($requirements['_scheme'])) {
if (0 === count($schemes)) {
$schemes = explode('|', $requirements['_scheme']);
}
unset($requirements['_scheme']);
@trigger_error(sprintf('The "_scheme" requirement of route "%s" in file "%s" is deprecated since version 2.2 and will be removed in 3.0. Use the "schemes" attribute instead.', $id, $path), E_USER_DEPRECATED);
}
$route = new Route($node->getAttribute('path'), $defaults, $requirements, $options, $node->getAttribute('host'), $schemes, $methods, $condition);
$collection->add($id, $route);
}
示例14: removeAttribute
/**
* Set an attribute on an element
*
* @param string $name
* @return bool
*/
public function removeAttribute($name)
{
list($namespace, $localName) = $this->resolveTagName($name);
if ($namespace != '') {
return parent::removeAttributeNS($namespace, $localName);
} else {
return parent::removeAttribute($name);
}
}
示例15: parseRoute
/**
* {@inheritDoc}
*/
protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
{
// the Symfony Routing component uses a path attribute since Symfony 2.2
// instead of the deprecated pattern attribute0
if (!$node->hasAttribute('path')) {
$node->setAttribute('path', $node->getAttribute('pattern'));
$node->removeAttribute('pattern');
}
if ($this->includeFormat) {
$path = $node->getAttribute('path');
// append format placeholder if not present
if (false === strpos($path, '{_format}')) {
$node->setAttribute('path', $path . '.{_format}');
}
// set format requirement if configured globally
$requirements = $node->getElementsByTagNameNS(self::NAMESPACE_URI, 'requirement');
$format = null;
for ($i = 0; $i < $requirements->length; $i++) {
$item = $requirements->item($i);
if ($item instanceof \DOMElement && $item->hasAttribute('_format')) {
$format = $item->getAttribute('_format');
break;
}
}
if (null === $format && !empty($this->formats)) {
$requirement = $node->ownerDocument->createElementNs(self::NAMESPACE_URI, 'requirement', implode('|', array_keys($this->formats)));
$requirement->setAttribute('key', '_format');
$node->appendChild($requirement);
}
}
// set the default format if configured
if (null !== $this->defaultFormat) {
$defaultFormatNode = $node->ownerDocument->createElementNS(self::NAMESPACE_URI, 'default', $this->defaultFormat);
$defaultFormatNode->setAttribute('key', '_format');
$node->appendChild($defaultFormatNode);
}
$options = $this->getOptions($node);
foreach ($options as $option) {
$node->appendChild($option);
}
$length = $node->childNodes->length;
for ($i = 0; $i < $length; $i++) {
$loopNode = $node->childNodes->item($i);
if ($loopNode->nodeType == XML_TEXT_NODE) {
continue;
}
$newNode = $node->ownerDocument->createElementNS(self::NAMESPACE_URI, $loopNode->nodeName, $loopNode->nodeValue);
foreach ($loopNode->attributes as $value) {
$newNode->setAttribute($value->name, $value->value);
}
$node->appendChild($newNode);
}
parent::parseRoute($collection, $node, $path);
}