M #-: Add --subtree to xpath.rb (#41)

This commit is contained in:
Jan Orel authored and GitHub committed 2020-06-24 16:35:43 +02:00
1 parent 3681055a5d
commit b9092758e2
1 file changed
+7 -3
+7 -3
View File
@@ -26,17 +26,21 @@ require 'pp'
opts = opts = GetoptLong.new(
[ '--stdin', '-s', GetoptLong::NO_ARGUMENT ],
[ '--subtree', '-t', GetoptLong::NO_ARGUMENT ],
[ '--base64', '-b', GetoptLong::REQUIRED_ARGUMENT ]
)
source = :stdin
tmp64 = ""
subtree = false
begin
opts.each do |opt, arg|
case opt
when '--stdin'
source = :stdin
when '--subtree'
subtree = true
when '--base64'
source = :b64
tmp64 = arg
@@ -65,10 +69,10 @@ ARGV.each do |xpath|
else
element = xml.elements[xpath.dup]
if !element.nil?
if element.class.method_defined?(:text)
values << ( element.text || '' )
else
if subtree
values << ( element.to_s || '' )
else
values << ( element.text || '' )
end
end
end