Sha256: 7c66a5dc830eabdbe3de7d69adc25c8d69a3977523ab5cefb507dd982e182cba

Contents?: true

Size: 857 Bytes

Versions: 3

Compression:

Stored size: 857 Bytes

Contents

#!/usr/bin/ruby
require "#{File.dirname($0)}/../smart"

doc = XML::Smart.open(File.dirname($0) + "/EXAMPLE.xml")
nodes = doc.root.find("/test/names/name")

puts "Original       : #{nodes.to_a.inspect}"

nodes.delete_if!{ |n| n.text == "egon"}
puts "#delete_if!    : #{nodes.to_a.inspect}"
puts "#length        : #{nodes.length}"
puts "#nitems        : #{nodes.nitems}"

nodes.delete_at!(2)
puts "#delete_at!(2) : #{nodes.to_a.inspect}"
puts "#length        : #{nodes.length}"
puts "#nitems        : #{nodes.nitems}"

nodes.delete_at!(-2)
puts "#delete_at!(-2): #{nodes.to_a.inspect}"
puts "#length        : #{nodes.length}"
puts "#nitems        : #{nodes.nitems}"

puts "\n"
nodes = doc.root.find("/test/names/name/@team")
puts "Original   : #{nodes.to_a.inspect}"
nodes.delete_if!{ |n| n.to_i % 2  != 0}
puts "#delete_if!: #{nodes.to_a.inspect}"

puts doc

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-xml-smart-0.1.12.1-i486-linux examples/delete.rb
ruby-xml-smart-0.1.12-i486-linux examples/delete.rb
ruby-xml-smart-0.1.11-i486-linux examples/delete.rb