Guest User

Untitled

a guest
Feb 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require "rexml/document"
  4.  
  5. string = <<EOF
  6. <kml><Placemark>
  7. <Icon><href>a.png</href> </Icon>
  8. <Icon><href>b.png</href> </Icon>
  9. </Placemark> </kml>
  10. EOF
  11. doc = REXML::Document.new string
  12.  
  13. $dest_fp = Hash.new
  14.  
  15. doc.elements.each("kml/Placemark") {
  16. |element| element.elements.each("Icon/href") {
  17. |icon| puts icon.text
  18. tmp = icon.text.split( "/" ).last()
  19. filename = tmp.split( "." ).first() + ".kml"
  20. puts filename
  21.  
  22. destfile = $dest_fb[filename]
  23. unless destfile
  24. destfile = File::open( destination, File::CREAT|File::TRUNC|File::WRONLY )
  25.  
  26. if destfile == nil
  27. puts( "Error: Destination file is not writable." )
  28. exit( 1 )
  29. end
  30.  
  31. $dest_fp[filename] = destfile
  32. destfile << "prefix"
  33. end
  34.  
  35. destfile << element
  36. }
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43. -->
  44.  
  45. roland@linux:~/work/kml> ./cc.rb
  46. a.png
  47. a.kml
  48. ./cc.rb:22: undefined method `[]' for nil:NilClass (NoMethodError)
  49. from ./cc.rb:16:in `each'
  50. from /usr/lib/ruby/site_ruby/1.8/rexml/element.rb:939:in `each'
  51. from /usr/lib/ruby/site_ruby/1.8/rexml/xpath.rb:53:in `each'
  52. from /usr/lib/ruby/site_ruby/1.8/rexml/element.rb:939:in `each'
  53. from ./cc.rb:16
  54. from ./cc.rb:15:in `each'
  55. from /usr/lib/ruby/site_ruby/1.8/rexml/element.rb:939:in `each'
  56. from /usr/lib/ruby/site_ruby/1.8/rexml/xpath.rb:53:in `each'
  57. from /usr/lib/ruby/site_ruby/1.8/rexml/element.rb:939:in `each'
  58. from ./cc.rb:15
Add Comment
Please, Sign In to add comment