Created
May 21, 2014 06:48
-
-
Save vparihar01/7a0c0d1254ac8f1fc74a to your computer and use it in GitHub Desktop.
Gitst to test xml parsing the quizes and its sample data
This file contains hidden or 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
| def parse_xml(xml) | |
| doc = Nokogiri::XML.parse(File.read(xml)) | |
| puts"___________________________" | |
| puts File.basename(xml) | |
| puts"___________________________" | |
| #doc = Nokogiri::XML.parse(File.read(Rails.public_path+"/courses/fundOfCoaching/v2_0/Course/pages/xml/1-2-6.xml")) | |
| #doc.root.elements.each do |i| | |
| # #puts "#{i['type']}!!!!!!!!!!!!!#{i['subtype']}" | |
| # #puts i["type"].eql? "interactive" | |
| # if (i["type"].eql? "interactive") && (i["subtype"].eql? "quiz") | |
| # i.elements.each do |j| | |
| # j.elements.each do |k| | |
| # puts ActionView::Base.full_sanitizer.sanitize(k["type"]) | |
| # end | |
| # end | |
| # end | |
| #end | |
| content = doc.xpath('//item[@type = "overlay"]//content') | |
| puts ActionView::Base.full_sanitizer.sanitize(content.text) | |
| puts "content print done -----------------------------" | |
| doc.xpath('//item[@subtype = "quiz"]//content//question').each do |i| | |
| puts " ------------ QUESTION TYPE ----------------" | |
| puts i["type"] | |
| #assessment = Assessment.new | |
| #assessment.attributes = { | |
| # title: legacy_quiz.title, | |
| # description: legacy_quiz.description, | |
| # assessment_type: "quiz" | |
| #} | |
| #assessment.id = legacy_quiz.quizID | |
| #assessment.save | |
| puts " ------------ !!!!!!Question TEXT!!!!! ----------------" | |
| puts ActionView::Base.full_sanitizer.sanitize(i.css("text").text) | |
| #puts i.css("answer").text | |
| i.css("answer").each do |k| | |
| puts " ------------ ########ANSWER TEXT ######## ----------------" | |
| puts ActionView::Base.full_sanitizer.sanitize(k.text) | |
| end | |
| end | |
| puts"___________end________________" | |
| end | |
| def migrate_quizes(course) | |
| course = LegacyCourses.find(course) | |
| #file_path = course.filePath | |
| course.legacy_course_units.each do |units| | |
| units.legacy_course_sections.each do |section| | |
| section.legacy_course_pages.each do |page| | |
| begin | |
| xml = get_file(course,page) | |
| parse_xml(xml) | |
| rescue | |
| puts "miss fire!!!!!" | |
| end | |
| end | |
| end | |
| end | |
| end | |
| j = 0 | |
| Dir.glob(Rails.public_path+"/courses/fundOfCoaching/v2_0/Course/pages/xml/*xml").each do |s| | |
| doc = Nokogiri::XML.parse(File.read(s)) | |
| doc.root.elements.each do |i| | |
| puts i["type"] | |
| puts i["type"].eql? "interactive" | |
| if i["type"].eql? "interactive" | |
| j=+1 | |
| end | |
| end | |
| end | |
| def parse_xml(xml) | |
| doc = Nokogiri::XML.parse(File.read(xml)) | |
| puts"___________________________" | |
| puts File.basename(xml) | |
| puts"___________________________" | |
| #doc = Nokogiri::XML.parse(File.read(Rails.public_path+"/courses/fundOfCoaching/v2_0/Course/pages/xml/1-2-6.xml")) | |
| doc.root.elements.each do |i| | |
| #puts "#{i['type']}!!!!!!!!!!!!!#{i['subtype']}" | |
| #puts i["type"].eql? "interactive" | |
| if (i["type"].eql? "interactive") && (i["subtype"].eql? "quiz") | |
| i.elements.each do |j| | |
| j.elements.each do |k| | |
| puts k["type"] | |
| end | |
| end | |
| end | |
| end | |
| doc.xpath('//item[@subtype = "quiz"]//content//question').each do |i| | |
| puts i.css("text") | |
| puts i.css("answer") | |
| i.css("answer").each do |k| | |
| puts k | |
| end | |
| end | |
| puts"___________end________________" | |
| end | |
| d.each do |i| | |
| puts i.css("text") | |
| puts i.css("answer") | |
| i.css("answer").each do |k| | |
| puts k | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment