Skip to content

Instantly share code, notes, and snippets.

@simonmd
Forked from elskwid/ps_template_parser.rb
Created March 27, 2012 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonmd/2219278 to your computer and use it in GitHub Desktop.
Save simonmd/2219278 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)
# This xml has items which then contain the information we want
# To keep this easy, we'll loop through the items then extract what we want from each of item
root.elements.each("item") do |item|
# Just output the ID of the item which is available in the <ID> node in the XML
puts item.elements['ID'].get_text
end
# save this for later
#root.each_element('//shortText').get_text.to_s {|word1| puts word1}
#magically somehow in the same "each element" section make it show the "longText" part too
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment