Skip to content

Commit

Permalink
Some initial tests of parsing the QTI XML.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfis committed Jan 13, 2021
1 parent b56a998 commit 8878c6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,38 @@

import argparse
from logzero import logger
from lxml import etree

qti_resource = {}

def main(args):
""" Main entry point of the app """
logger.info("Main program starting point.")
logger.info(args)

xml_doc = etree.parse(args.filename)

for xml_resource in xml_doc.getroot().findall(".//{http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1}resource[@type='imsqti_xmlv1p2']"):
this_resource_id = xml_resource.get("identifier")
qti_resource[this_resource_id] = {}
qti_resource[this_resource_id]['id'] = this_resource_id
qti_resource[this_resource_id]['href'] = xml_resource.find("{http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1}file").get("href")
qti_resource[this_resource_id]['title'] = etree.parse(qti_resource[xml_resource.get("identifier")]['href']).getroot().find("{http://www.imsglobal.org/xsd/ims_qtiasiv1p2}assessment").get("title")
qti_resource[this_resource_id]['items'] = {}

for xml_item in etree.parse(qti_resource[xml_resource.get("identifier")]['href']).getroot().findall(".//{http://www.imsglobal.org/xsd/ims_qtiasiv1p2}item"):
this_item_id = xml_item.get("ident")
qti_resource[this_resource_id]['items'][this_item_id] = {}
qti_resource[this_resource_id]['items'][this_item_id]['id'] = this_item_id
qti_resource[this_resource_id]['items'][this_item_id]['title'] = xml_item.find("{http://www.imsglobal.org/xsd/ims_qtiasiv1p2}presentation/{http://www.imsglobal.org/xsd/ims_qtiasiv1p2}material/{http://www.imsglobal.org/xsd/ims_qtiasiv1p2}mattext").text

for assessment in qti_resource:
a = qti_resource[assessment]
print(a['id'] + " " + a['title'])
for item in a['items']:
i = a['items'][item]
print(i['id'] + i['title'])


if __name__ == "__main__":
""" This is executed when run from the command line """
Expand Down
1 change: 1 addition & 0 deletions src/parser/imsmanifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1

0 comments on commit 8878c6d

Please sign in to comment.