Class: XML::DOM::Attr

Inherits:
Node
  • Object
show all
Defined in:
lib/xml/dom/core.rb,
lib/xml/dom2/attr.rb,
lib/xml/dom/digest.rb,
lib/xml/dom2/xpath.rb

Overview

Class XML::DOM::Attr

superclass

Node

Constant Summary

Constants inherited from Node

Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAGMENT_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::ENTITY_NODE, Node::ENTITY_REFERENCE_NODE, Node::NODE_NODE, Node::NOTATION_NODE, Node::PROCESSING_INSTRUCTION_NODE, Node::TEXT_NODE

Instance Method Summary collapse

Methods inherited from Node

#+, #<=>, #==, #[], #[]=, #__collectAncestorNS, #__collectDescendatNS, #__sibling, #_ancestor, #_child, #_descendant, #_following, #_fsibling, #_getChildIndex, #_getMyLocation, #_getMyLocationInXPath, #_getNodeByAbsoluteLocationTerm, #_insertNodes, #_matchAttribute?, #_matchNode?, #_matchNodeAttributes?, #_matchNodeType?, #_nodesByLocationTerms, #_nodesByRelativeLocationTerm, #_preceding, #_psibling, #_removeFromTree, #_removeNode, #_searchID, #accept, #accept_name, #appendChild, #attributes, #childNodes, #childNodes=, #children_accept, #children_accept_name, #each, #firstChild, #getNodesByXPath, #getNodesByXPointer, #hasAttributes, #hasChildNodes, #insertBefore, #inspect, #isSupported, #lastChild, #makeXPointer, #nextSibling, #ownerDocument, #ownerDocument=, #parentNode, #parentNode=, #previousSibling, #removeChild, #replaceChild, #trim

Constructor Details

#initialize(name, *text) ⇒ Attr

Class Methods

--- Attr.new(name = nil, *text)

create a new Attr.



1775
1776
1777
1778
1779
1780
# File 'lib/xml/dom/core.rb', line 1775

def initialize(name = nil, *text)
  super(text)
  raise "parameter error" if !name
  @name =  name
  @name.freeze
end

Instance Method Details

#_checkNode(node) ⇒ Object



1904
1905
1906
1907
1908
1909
# File 'lib/xml/dom/core.rb', line 1904

def _checkNode(node)
  unless node.nodeType == TEXT_NODE ||
      node.nodeType == ENTITY_REFERENCE_NODE
    raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
  end
end

#cloneNode(deep = true) ⇒ Object

DOM


1873
1874
1875
# File 'lib/xml/dom/core.rb', line 1873

def cloneNode(deep = true)
  super(deep, @name)
end

#dump(depth = 0) ⇒ Object

— Attr#dump(depth = 0)

dump the Attr.



1861
1862
1863
1864
# File 'lib/xml/dom/core.rb', line 1861

def dump(depth = 0)
  print ' ' * depth * 2
  print "// #{self.to_s}\n"
end

#getDigest(algorithm = Digest::MD5, force = false) ⇒ Object



60
61
62
63
64
# File 'lib/xml/dom/digest.rb', line 60

def getDigest(algorithm = Digest::MD5, force = false)
  (!force && @digest) ||
    @digest = algorithm.digest([ATTRIBUTE_NODE].pack("N") +
                               DOM.tou16(nodeName) + "\0\0" + DOM.tou16(nodeValue))
end

#localnameObject

DOM2


199
# File 'lib/xml/dom2/attr.rb', line 199

def localname; @localname; end

#makeXPathObject



388
389
390
# File 'lib/xml/dom2/xpath.rb', line 388

def makeXPath
  '@' + nodeName
end

#namespaceURIObject

DOM2


181
# File 'lib/xml/dom2/attr.rb', line 181

def namespaceURI; @uri; end

#nodeNameObject Also known as: name

DOM


1802
1803
1804
# File 'lib/xml/dom/core.rb', line 1802

def nodeName
  @name
end

#nodeTypeObject

DOM


1791
1792
1793
# File 'lib/xml/dom/core.rb', line 1791

def nodeType
  ATTRIBUTE_NODE
end

#nodeValueObject Also known as: value

DOM


1813
1814
1815
1816
1817
1818
1819
# File 'lib/xml/dom/core.rb', line 1813

def nodeValue
  ret = ""
  @children.each do |child|
    ret << child.nodeValue
  end if @children
  ret
end

#nodeValue=(text) ⇒ Object Also known as: value=

DOM


1828
1829
1830
# File 'lib/xml/dom/core.rb', line 1828

def nodeValue=(text)
  self.childNodes = [text]
end

#ownerElementObject

DOM2


202
# File 'lib/xml/dom2/attr.rb', line 202

def ownerElement; @ownerElement; end

#ownerElement=(elem) ⇒ Object



203
# File 'lib/xml/dom2/attr.rb', line 203

def ownerElement=(elem); @ownerElement = elem; end

#prefixObject

DOM2


184
# File 'lib/xml/dom2/attr.rb', line 184

def prefix; @prefix; end

#prefix=(prefix) ⇒ Object

DOM2


187
188
189
190
191
192
193
194
195
196
# File 'lib/xml/dom2/attr.rb', line 187

def prefix=(prefix);
  ## to be checked

  @ownerElement.removeAttributeNode(self) if @ownerElement
  @prefix = prefix
  @name = @prefix + ':' + @localname
  @ownerElement.setAttributeNode(self) if @ownerElement
  @prefix.freeze
  @name.freeze
end

#specifiedObject

DOM


1901
# File 'lib/xml/dom/core.rb', line 1901

def specified; @specified; end

#specified=(is_specified) ⇒ Object



1902
# File 'lib/xml/dom/core.rb', line 1902

def specified=(is_specified); @specified = is_specified; end

#to_sObject

— Attr#to_s()

return the string representation of the Attr.



1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
# File 'lib/xml/dom/core.rb', line 1837

def to_s
  value = ""
  nodeValue.each_byte do |code|
    case code
    when 9, 10, 13
      value << sprintf("&#x%X;", code)
    when ?&
      value << "&amp;"
    when ?"
      value << "&quot;"
    when ?<
      value << "&lt;"
    else
      value << code
    end
  end
  "#{@name}=\"#{value}\""
end