-
-
Save elskwid/1713536 to your computer and use it in GitHub Desktop.
Powerscribe templates XML parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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