本文整理汇总了PHP中DOMNode::hasAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMNode::hasAttribute方法的具体用法?PHP DOMNode::hasAttribute怎么用?PHP DOMNode::hasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMNode
的用法示例。
在下文中一共展示了DOMNode::hasAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getXsdElementName
/**
* @param DOMNode $node
* @return string of type
*/
public static function getXsdElementName(DOMNode $node)
{
if ($node->localName == 'element' || $node->localName == 'attribute') {
if ($node->hasAttribute('name')) {
return $node->getAttribute('name');
}
return null;
}
// nowhere else to search
if (is_null($node->parentNode)) {
return null;
}
return self::getXsdElementName($node->parentNode);
}
示例2: parse
public function parse(DOMNode $element)
{
if ($element->hasAttribute('name')) {
$this->name = $element->getAttribute('name');
}
if ($element->hasAttribute('type')) {
$this->type = $element->getAttribute('type');
}
for ($i = 0; $i < $element->childNodes->length; $i++) {
$childElement = $element->childNodes->item($i);
if ($childElement->parentNode !== $element) {
continue;
}
if ($childElement instanceof DOMComment || $childElement instanceof DOMText) {
continue;
}
switch ($childElement->nodeName) {
case 'part':
$this->parts[] = new Ezer_XmlVariable($childElement);
break;
default:
throw new Ezer_XmlPersistanceElementNotMappedException($childElement->nodeName);
}
}
}
示例3: process
function process(DOMNode $current_node)
{
global $filter_args, $filter_tags, $filter_mandatory, $bbcode;
if ($current_node instanceof DOMElement || $current_node instanceof DOMDocument) {
// Recursion. I need iterator_to_array(), because it's likely
// that node list will be modified.
foreach (iterator_to_array($current_node->childNodes) as $node) {
process($node);
}
// BBCode hack is NOT allowed to exist
if ($current_node->tagName === 'bbcodehack') {
$value = $current_node->hasAttribute('value') ? $current_node->getAttribute('value') : NULL;
$nodes = $current_node->hasAttribute('pre') ? $current_node->getAttribute('pre') : $current_node->childNodes;
$nodes = $bbcode[$current_node->getAttribute('name')]['callback']($current_node->ownerDocument, $nodes, $value, array('borked' => $current_node->hasAttribute('borked')));
if (!is_array($nodes)) {
$nodes = array($nodes);
}
foreach ($nodes as $node) {
$current_node->parentNode->insertBefore($node, $current_node);
}
// Remove bbcodehack from DOM
$current_node->parentNode->removeChild($current_node);
} elseif ($current_node->tagName && !isset($filter_tags[$current_node->tagName])) {
while ($current_node->hasChildNodes()) {
$current_node->parentNode->insertBefore($current_node->childNodes->item(0), $current_node);
}
$current_node->parentNode->removeChild($current_node);
} else {
if ($current_node->hasAttributes()) {
// I need iterator_to_array, as I modify attributes
// list while iterating.
foreach (iterator_to_array($current_node->attributes) as $attr) {
$attribute = isset($filter_tags[$current_node->tagName][$attr->name]) ? $filter_tags[$current_node->tagName][$attr->name] : (isset($filter_args[$attr->name]) ? $filter_args[$attr->name] : NULL);
if (!$attribute) {
$current_node->removeAttribute($attr->name);
} elseif (!is_bool($attribute)) {
$value = $attribute($attr->value, $current_node);
if ($value === NULL) {
$current_node->removeAttribute($attr->name);
} else {
$current_node->setAttribute($attr->name, $value);
}
}
}
}
if (isset($filter_mandatory[$current_node->tagName])) {
foreach ($filter_mandatory[$current_node->tagName] as $attr => $value) {
if (!$current_node->hasAttribute($attr)) {
$current_node->setAttribute($attr, $value);
}
}
}
}
} elseif ($current_node instanceof DOMComment) {
// Unsafe because of conditional comments
$current_node->parentNode->removeChild($current_node);
}
}
示例4: 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);
}
}
示例5: processDataTag
private function processDataTag( DOMNode $node ) {
if( $node->hasAttribute( DATA_TYPE_ATTRIBUTE_NAME ) ) {
switch( $node->getAttribute( DEPENDENCY_TYPE_ATTRIBUTE_NAME ) ) {
case DATA_TYPE_STREAM_VALUE:
/******* nothing for now
$url = $this->buildURL( MODULE_STREAM_PATH . $node->nodeValue );
if( $this->url_exists( $url ) ) {
$this->xml->load( $url );
}
**********/
break;
case DATA_TYPE_PROCESSOR_VALUE:
break;
case DATA_TYPE_DYNAMICFILE_VALUE:
if ( file_exists( MODULE_FILE_PATH . $node->nodeValue ) ) {
ob_start();
$file = MODULE_FILE_PATH . $node->nodeValue;
include $file;
$this->dynamicFileOutput .= ob_get_contents();
ob_end_clean();
}
break;
case DATA_TYPE_STATICFILE_VALUE:
if ( file_exists( MODULE_FILE_PATH . $node->nodeValue ) ) {
$this->staticFileOutput .= file_get_contents( MODULE_FILE_PATH . $node->nodeValue );
} else {
//echo "loading: " . MODULE_FILE_PATH . $node->nodeValue;
}
break;
}
}
}
示例6: getGenerateText
/**
* Return the string for generating a new password for the form prompt.
* @param DOMNode $form_node The form node that has the generate attribute
*/
protected function getGenerateText($form_node)
{
if ($form_node->hasAttribute("generate")) {
return $form_node->getAttribute("generate");
} elseif ($this->hasHeader("generate")) {
return $this->getHeader("generate");
}
return null;
}
示例7: isSigImage
/**
* Determine if node contains HTML signature image data.
*
* @param DOMNode $node The node to check.
* @param boolean $strip Strip attribute from the node?
*
* @return boolean True if node contains image data.
*/
public static function isSigImage(DOMNode $node, $strip = false)
{
if (strcasecmp($node->tagName, 'IMG') === 0 && $node->hasAttribute(self::HTMLSIG_ATTR)) {
if ($strip) {
$node->removeAttribute(self::HTMLSIG_ATTR);
}
return true;
}
return false;
}
示例8: isValidNodeAttrs
/**
* Check for a list of attributes if current node is valid
*
* @param DOMNode $node to check if valid
* @param array $attrs to test if in $node
*
* @return boolean true if $node is valid for $attrs, false otherwise
*/
public static function isValidNodeAttrs($node, $attrs)
{
foreach ($attrs as $attr) {
$val = '';
if (strpos($attr, '=') !== false) {
list($attr, $val) = explode('=', $attr);
}
if (!$node->hasAttribute($attr) || !empty($val) && $node->getAttribute($attr) !== $val) {
return false;
}
}
return true;
}
示例9: setNode
public function setNode(DOMNode $node)
{
if (!$this->parentNode) {
throw new Exception('Parent Node must be set before actual Node');
}
$this->externalNode = $node;
$this->element = $this->doc->createElement($this->getTagName());
if ($this->keepAttributes) {
foreach ($this->externalNode->attributes as $attr) {
if ($attr->name == 'class') {
$this->className = strlen($this->className) ? $this->className . ' ' . $attr->value : $attr->value;
} elseif ($attr->name == "data-pxe-attributes") {
$attributes = json_decode($attr->value);
foreach ($attributes as $name => $value) {
$this->element->setAttribute($name, $value);
}
} elseif (substr($attr->name, 0, 8) != 'data-pxe' && substr($attr->name, 0, 7) !== 'data-ca') {
if (!array_key_exists($attr->name, $this->element->attributes)) {
$this->element->setAttribute($attr->name, $attr->value);
}
}
}
}
// Keep attribute explicitly asked for by editor regardless of how smart you think you are.
foreach ($this->attributes as $key => $value) {
if ($this->element->hasAttribute($key)) {
$value = $this->element->getAttribute($key)->value . ' ' . $value;
}
$this->element->setAttribute($key, $value);
}
if ($this->className) {
$this->element->setAttribute('class', $this->className);
}
$this->parentNode->appendChild($this->element);
return $this;
}
示例10: attr
/** @inheritDoc */
public function attr($name = null, $fallback = null)
{
if ($this->is('#element')) {
// We consider only regular DOM elements can have attributes. Text nodes,
// comments, etc... don't have ones.
if (is_null($name)) {
// No argument given: return the whole collection.
return new AttrCollection($this->source->attributes);
} else {
if ($this->source->hasAttribute($name)) {
return $this->source->getAttribute($name);
} else {
return $fallback;
}
}
} else {
return $fallback;
}
}
示例11: parseTextConstruct
/**
* Extract content appropriately from atom text constructs
*
* Because of different rules applied to the content element and other text
* constructs, they are deployed as separate functions, but they share quite
* a bit of processing. This method performs the core common process, which is
* to apply the rules for different mime types in order to extract the content.
*
* @param DOMNode $content the text construct node to be parsed
* @return String
* @author James Stewart
**/
protected function parseTextConstruct(DOMNode $content)
{
if ($content->hasAttribute('type')) {
$type = $content->getAttribute('type');
} else {
$type = 'text';
}
if (strpos($type, 'text/') === 0) {
$type = 'text';
}
switch ($type) {
case 'text':
return $content->nodeValue;
break;
case 'html':
return str_replace('<', '<', $content->nodeValue);
break;
case 'xhtml':
$container = $content->getElementsByTagName('div');
if ($container->length == 0) {
return false;
}
$contents = $container->item(0);
if ($contents->hasChildNodes()) {
/* Iterate through, applying xml:base and store the result */
$result = '';
foreach ($contents->childNodes as $node) {
$result .= $this->traverseNode($node);
}
return utf8_decode($result);
}
break;
case preg_match('@^[a-zA-Z]+/[a-zA-Z+]*xml@i', $type) > 0:
return $content;
break;
case 'application/octet-stream':
default:
return base64_decode(trim($content->nodeValue));
break;
}
return false;
}
示例12: html2ooNodeInt
/**
* @param \DOMNode $srcNode
* @param bool $lineNumbered
* @param bool $inP
*
* @return \DOMNode[]
* @throws \Exception
*/
protected function html2ooNodeInt($srcNode, $lineNumbered, $inP)
{
switch ($srcNode->nodeType) {
case XML_ELEMENT_NODE:
/** @var \DOMElement $srcNode */
if ($this->DEBUG) {
echo "Element - " . $srcNode->nodeName . " / Children: " . count($srcNode->childNodes) . "<br>";
}
$needsIntermediateP = false;
switch ($srcNode->nodeName) {
case 'span':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span');
if ($srcNode->hasAttribute('class')) {
$classes = explode(' ', $srcNode->getAttribute('class'));
if (in_array('underline', $classes)) {
$dstEl->setAttribute('text:style-name', 'AntragsgruenUnderlined');
}
if (in_array('strike', $classes)) {
$dstEl->setAttribute('text:style-name', 'AntragsgruenStrike');
}
if (in_array('ins', $classes)) {
$dstEl->setAttribute('text:style-name', 'AntragsgruenIns');
}
if (in_array('inserted', $classes)) {
$dstEl->setAttribute('text:style-name', 'AntragsgruenIns');
}
if (in_array('del', $classes)) {
$dstEl->setAttribute('text:style-name', 'AntragsgruenDel');
}
if (in_array('deleted', $classes)) {
$dstEl->setAttribute('text:style-name', 'AntragsgruenDel');
}
if (in_array('superscript', $classes)) {
$dstEl->setAttribute('text:style-name', 'AntragsgruenSup');
}
if (in_array('subscript', $classes)) {
$dstEl->setAttribute('text:style-name', 'AntragsgruenSub');
}
}
break;
case 'b':
case 'strong':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span');
$dstEl->setAttribute('text:style-name', 'AntragsgruenBold');
break;
case 'i':
case 'em':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span');
$dstEl->setAttribute('text:style-name', 'AntragsgruenItalic');
break;
case 's':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span');
$dstEl->setAttribute('text:style-name', 'AntragsgruenStrike');
break;
case 'u':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span');
$dstEl->setAttribute('text:style-name', 'AntragsgruenUnderlined');
break;
case 'sub':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span');
$dstEl->setAttribute('text:style-name', 'AntragsgruenSub');
break;
case 'sup':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span');
$dstEl->setAttribute('text:style-name', 'AntragsgruenSup');
break;
case 'br':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'line-break');
break;
case 'del':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span');
$dstEl->setAttribute('text:style-name', 'AntragsgruenDel');
break;
case 'ins':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span');
$dstEl->setAttribute('text:style-name', 'AntragsgruenIns');
break;
case 'a':
$dstEl = $this->doc->createElementNS(static::NS_TEXT, 'a');
try {
$attr = $srcNode->getAttribute('href');
if ($attr) {
$dstEl->setAttribute('xlink:href', $attr);
}
} catch (\Exception $e) {
}
break;
case 'p':
case 'div':
if ($inP) {
$dstEl = $this->createNodeWithBaseStyle('span', $lineNumbered);
} else {
//.........这里部分代码省略.........
示例13: AddClass
/**
* Add the given class to the DOM
* @param DOMNode $oClassNode
* @param string $sModuleName The name of the module in which this class is declared
* @throws Exception
*/
public function AddClass(DOMNode $oClassNode, $sModuleName)
{
if ($oClassNode->hasAttribute('id')) {
$sClassName = $oClassNode->GetAttribute('id');
} else {
throw new Exception('ModelFactory::AddClass: Cannot add a class with no name');
}
if ($this->ClassNameExists($oClassNode->getAttribute('id'))) {
throw new Exception("ModelFactory::AddClass: Cannot add the already existing class {$sClassName}");
}
$sParentClass = $oClassNode->GetChildText('parent', '');
$oParentNode = $this->GetClass($sParentClass);
if ($oParentNode == null) {
throw new Exception("ModelFactory::AddClass: Cannot find the parent class of '{$sClassName}': '{$sParentClass}'");
} else {
if ($sModuleName != '') {
$oClassNode->SetAttribute('_created_in', $sModuleName);
}
$oParentNode->AddChildNode($this->oDOMDocument->importNode($oClassNode, true));
if (substr($sParentClass, 0, 1) == '/') {
// Remove the leading slash character
$oParentNameNode = $oClassNode->GetOptionalElement('parent')->firstChild;
// Get the DOMCharacterData node
$oParentNameNode->data = substr($sParentClass, 1);
}
}
}
示例14: addReportSelector
/**
* Adds a report selector
* @param DOMNode $node The node we are adding the selector on.
* @param array $options. Array ofoptions. should include keys: 'printf', 'printfargs', 'reportiew' or they should be set as attributes on the node. 'reportform' the form in the report view we want to select (Defaults to primary_form)
* other optional keys are 'updateval' and 'updatedisp' which are names of elements to update the name and id of. If not set, then it is 'updateval'=$id:value and 'updatedisp=$id:display
* and 'value' which contains the current db value
* and 'display' which contains the current display value
*/
public function addReportSelector($obj, $node, $options = array())
{
if ($obj instanceof I2CE_Page) {
$template = $obj->getTemplate();
} else {
$template = $obj;
}
if (!$template instanceof I2CE_Template) {
return false;
}
if (!$node instanceof DOMElement) {
return false;
}
if (!$node->hasAttribute('id') || !($id = $node->getAttribute('id'))) {
return false;
}
if (!is_array($options)) {
return false;
}
if ($node->hasAttribute('reportview')) {
$options['reportview'] = $node->getAttribute('reportview');
$node->removeAttribute('reportview');
}
if ($node->hasAttribute('reportform')) {
$options['reportform'] = $node->getAttribute('reportform');
$node->removeAttribute('reportform');
}
if ($node->hasAttribute('printf')) {
$options['printf'] = $node->getAttribute('printf');
$node->removeAttribute('printf');
}
if ($node->hasAttribute('printfargs')) {
$options['printfargs'] = explode(',', $node->getAttribute('printfargs'));
$node->removeAttribute('printfargs');
}
if ($node->hasAttribute('contentid')) {
$options['contentid'] = $node->getAttribute('contentid');
$node->removeAttribute('contentid');
}
if (!array_key_exists('reportview', $options) || !($reportview = $options['reportview']) || !I2CE::getConfig()->is_parent("/modules/CustomReports/reportViews/{$reportview}") || !array_key_exists('printf', $options) || !$options['printf'] || !array_key_exists('printfargs', $options) || !is_array($options['printfargs']) || count($options['printfargs']) == 0) {
return false;
}
if (!array_key_exists('value', $options)) {
$options['value'] = '';
}
if (!array_key_exists('display', $options)) {
$options['display'] = '';
}
if (!is_string($options['display']) || strlen(trim($options['display'])) == 0) {
I2CE::getConfig()->setIfIsSet($display['config'], "/modules/CustomReports/displays/Selector/display_options/select_value");
if (!is_string($options['display']) || strlen(trim($options['display'])) == 0) {
$options['display'] = 'Select Value';
}
}
if (!array_key_exists('value', $options)) {
$options['value'] = '';
}
if (!($mainNode = $template->loadFile("reportselector.html", "div")) instanceof DOMElement) {
return false;
}
if (!($windowNode = $template->getElementByName("window", 0, $mainNode)) instanceof DOMNode) {
return false;
}
if (!($dispNode = $template->getElementByName("display", 0, $mainNode)) instanceof DOMNode) {
return false;
}
if (!($valNode = $template->getElementByName("value", 0, $mainNode)) instanceof DOMNode) {
return false;
}
if (!($selectNode = $template->getElementByName("selector", 0, $mainNode)) instanceof DOMNode) {
return false;
}
$contentNode = $template->appendFileByName("reportselector_content.html", "div", "content", 0, $mainNode);
if (!$contentNode instanceof DOMElement) {
return false;
}
$node->appendChild($mainNode);
//we are good to go
$windowNode->setAttribute('id', $id . ':window');
$dispNode->setAttribute('id', $id . ':display');
$template->addClass($dispNode, $id . '_toggle');
$template->addTextNode($dispNode, $options['display']);
$valNode->setAttribute('id', $id . ':value');
$valNode->setAttribute('value', $options['value']);
$valNode->setAttribute('name', $id);
$jsSelect = "if (reportselectors && reportselectors['" . addslashes($id) . "']) {reportselectors['" . addslashes($id) . "'].show(); return false;} else { return false;}";
$selectNode->setAttribute('onClick', $jsSelect);
if (!array_key_exists('allow_clear', $options)) {
$options['allow_clear'] = true;
}
if (($clearNode = $template->getElementByName("clear_value_button", 0, $mainNode)) instanceof DOMNode) {
if ($options['allow_clear']) {
//.........这里部分代码省略.........
示例15: addChoice
/**
* Adds a choice to the current ones.
*
* This method should only be used internally.
*
* @param \DOMNode $node A \DOMNode
*
* @throws \LogicException When choice provided is not multiple nor radio
*/
public function addChoice(\DOMNode $node)
{
if (!$this->multiple && 'radio' != $this->type) {
throw new \LogicException(sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
}
$this->options[] = $value = $node->hasAttribute('value') ? $node->getAttribute('value') : '1';
if ($node->getAttribute('checked')) {
$this->value = $value;
}
}