Skip to content

Instantly share code, notes, and snippets.

@Alfaj0r
Forked from elskwid/ps_template_parser.rb
Created January 31, 2012 23:10
Show Gist options
  • Save Alfaj0r/1713679 to your computer and use it in GitHub Desktop.
Save Alfaj0r/1713679 to your computer and use it in GitHub Desktop.
Powerscribe templates XML parsing
#!/usr/bin/env ruby
require 'rexml/document'
include REXML
#open the XML file exported from Powerscribe
# Ruby lets us open the file in a block (thereby closing it when it's done)
File.open("Voice.xml") do |file|
# The "block" is that do ... end syntax and |file| is a reference to the file we've opened
doc = Document.new(file)
root = doc.root
#for each element of listed in the XML file we want to:
# display the "shortText" (which is the title of the Template)
# display the "longText" (which is the actual text of the Template)
root.elements.each("item") do |item|
# Just output the field of the item which is available as a node in the XML
puts "Template title:"
puts item.elements['shortText'].get_text
puts "Template text:"
puts item.elements['longText'].get_text
puts "***********************************"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment