Class: VtdXml::Node

Inherits:
Object
  • Object
show all
Includes:
Navigation
Defined in:
lib/vtd_xml/document.rb

Instance Method Summary collapse

Methods included from Navigation

#clear_xpath_namespaces, #register_namespaces, #xpath

Constructor Details

#initialize(start_index, navigator, pilot, modifier) ⇒ Node



131
132
133
134
135
136
137
# File 'lib/vtd_xml/document.rb', line 131

def initialize(start_index, navigator, pilot, modifier)
  @start_index = start_index
  @navigator = navigator
  @pilot = pilot
  @modifier = modifier
  @text_for = text_for(start_index)
end

Instance Method Details

#removeObject



143
144
145
146
# File 'lib/vtd_xml/document.rb', line 143

def remove
  @navigator.recover_node(@start_index)
  @modifier.remove()
end

#search(xpath) ⇒ Object



166
167
168
169
# File 'lib/vtd_xml/document.rb', line 166

def search(xpath)
  @navigator.recover_node(@start_index)
  super(xpath)
end

#text_for(index) ⇒ Object

Beware of TCO!



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/vtd_xml/document.rb', line 149

def text_for(index)
  if index != -1
    case @navigator.get_token_type(index)
      when VTDGen::TOKEN_STARTING_TAG #element node
        text_for(@navigator.text())
      when VTDGen::TOKEN_ATTR_NAME #attribute node
        text_for(@navigator.get_attr_val(@navigator.to_string(index)))
      when VTDGen::TOKEN_ATTR_VAL #attribute value
        @navigator.to_normalized_string(index)
      when VTDGen::TOKEN_CHARACTER_DATA #text node
        @navigator.to_normalized_string(index)
      when VTDGen::TOKEN_DOCUMENT #root node, don't think they can have text values
        @navigator.to_normalized_string(index)
    end
  end
end

#to_sObject



139
140
141
# File 'lib/vtd_xml/document.rb', line 139

def to_s
  @text_for
end