Class: XML::DOM::ProcessingInstruction

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

Overview

Class XML::DOM::ProcessingInstruction

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, #_checkNode, #_child, #_descendant, #_following, #_fsibling, #_getChildIndex, #_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, #localname, #makeXPath, #makeXPointer, #namespaceURI, #nextSibling, #nodeValue=, #ownerDocument, #ownerDocument=, #parentNode, #parentNode=, #prefix, #prefix=, #previousSibling, #removeChild, #replaceChild, #trim

Constructor Details

#initialize(target = nil, data = nil) ⇒ ProcessingInstruction

new(target, data)

target: String
data: String


3127
3128
3129
3130
3131
3132
3133
3134
3135
# File 'lib/xml/dom/core.rb', line 3127

def initialize(target = nil, data = nil)
  super()
  raise "parameter error" if !data
  @target = target.freeze
  @data = data.freeze
  @value = target.dup
  @value << " #{data}" if data != ""
  @value.freeze
end

Instance Method Details

#_getMyLocation(parent) ⇒ Object



3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
# File 'lib/xml/dom/core.rb', line 3247

def _getMyLocation(parent)
  index = 1
  parent.childNodes do |child|
    if child == self
      return "child(#{index},#pi)"
    end
    if child.nodeType == PROCESSING_INSTRUCTION_NODE
      index += 1
    end
  end
  nil
end

#_getMyLocationInXPath(parent) ⇒ Object



376
377
378
379
380
381
# File 'lib/xml/dom2/xpath.rb', line 376

def _getMyLocationInXPath(parent)
  n = parent.childNodes.to_a.select { |i|
    i.nodeType == PROCESSING_INSTRUCTION_NODE
  }.index(self)
  "processing-instruction()[#{n + 1}]"
end

#cloneNode(deep = true) ⇒ Object

DOM


3267
3268
3269
# File 'lib/xml/dom/core.rb', line 3267

def cloneNode(deep = true)
  super(deep, @target.dup, @data.dup)
end

#dataObject

DOM


3193
3194
3195
# File 'lib/xml/dom/core.rb', line 3193

def data
  @data
end

#data=(p) ⇒ Object

DOM


3204
3205
3206
3207
3208
3209
# File 'lib/xml/dom/core.rb', line 3204

def data=(p)
  @data = p.freeze
  @value = @target.dup
  @value << " #{@data}" if @data != ""
  @value.freeze
end

#dump(depth = 0) ⇒ Object

— ProcessingInstruction#dump(depth = 0)

dumps the ProcessingInstruction.



3242
3243
3244
3245
# File 'lib/xml/dom/core.rb', line 3242

def dump(depth = 0)
  print ' ' * depth * 2
  print "<?#{@value.inspect}?>\n"
end

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



52
53
54
55
56
# File 'lib/xml/dom/digest.rb', line 52

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

#nodeNameObject

DOM


3157
3158
3159
# File 'lib/xml/dom/core.rb', line 3157

def nodeName
  "#proccessing-instruction"
end

#nodeTypeObject

DOM


3146
3147
3148
# File 'lib/xml/dom/core.rb', line 3146

def nodeType
  PROCESSING_INSTRUCTION_NODE
end

#nodeValueObject

DOM


3219
3220
3221
# File 'lib/xml/dom/core.rb', line 3219

def nodeValue
  @value
end

#targetObject

DOM


3168
3169
3170
# File 'lib/xml/dom/core.rb', line 3168

def target
  @target
end

#target=(p) ⇒ Object

DOM


3179
3180
3181
3182
3183
3184
# File 'lib/xml/dom/core.rb', line 3179

def target=(p)
  @target = p.freeze
  @value = @target.dup
  @value << " #{@data}" if @data != ""
  @value.freeze
end

#to_sObject

— ProcessingInstruction#to_s

returns the string representation of the ProcessingInstruction.



3231
3232
3233
3234
3235
# File 'lib/xml/dom/core.rb', line 3231

def to_s
  ret = "<?#{@value}?>"
  ret << "\n" if parentNode.nodeType == DOCUMENT_NODE
  ret
end