Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require "rexml/document"
- string = <<EOF
- <kml><Placemark>
- <Icon><href>a.png</href> </Icon>
- <Icon><href>b.png</href> </Icon>
- </Placemark> </kml>
- EOF
- doc = REXML::Document.new string
- $dest_fp = Hash.new
- doc.elements.each("kml/Placemark") {
- |element| element.elements.each("Icon/href") {
- |icon| puts icon.text
- tmp = icon.text.split( "/" ).last()
- filename = tmp.split( "." ).first() + ".kml"
- puts filename
- destfile = $dest_fb[filename]
- unless destfile
- destfile = File::open( destination, File::CREAT|File::TRUNC|File::WRONLY )
- if destfile == nil
- puts( "Error: Destination file is not writable." )
- exit( 1 )
- end
- $dest_fp[filename] = destfile
- destfile << "prefix"
- end
- destfile << element
- }
- }
- -->
- roland@linux:~/work/kml> ./cc.rb
- a.png
- a.kml
- ./cc.rb:22: undefined method `[]' for nil:NilClass (NoMethodError)
- from ./cc.rb:16:in `each'
- from /usr/lib/ruby/site_ruby/1.8/rexml/element.rb:939:in `each'
- from /usr/lib/ruby/site_ruby/1.8/rexml/xpath.rb:53:in `each'
- from /usr/lib/ruby/site_ruby/1.8/rexml/element.rb:939:in `each'
- from ./cc.rb:16
- from ./cc.rb:15:in `each'
- from /usr/lib/ruby/site_ruby/1.8/rexml/element.rb:939:in `each'
- from /usr/lib/ruby/site_ruby/1.8/rexml/xpath.rb:53:in `each'
- from /usr/lib/ruby/site_ruby/1.8/rexml/element.rb:939:in `each'
- from ./cc.rb:15
Add Comment
Please, Sign In to add comment