$ python3
>>> import os
>>> import os.path
>>> TEST_DATA_DIR = '.../data_xml20081126')
>>> os.chdir(TEST_DATA_DIR)
>>> from pyslet.xml import structures
>>> d = structures.Document(base_uri='readFile.xml')
>>> d.read()
...
in the path with the location of the data dir)
d
in more detail
bytes(d)
doesnt tell you much -- that almost certainly re-serialises d
into a bytestream
type(d)
, and dir(d)
to look at the d
object type, and what attributes it has that can be explored
dir(d)
['ChildElement', 'Create', 'DiffString', 'GenerateXML', 'GetBase', 'GetChildClass', 'GetChildren', 'G
etElementByID', 'GetElementClass', 'GetLang', 'GetSpace', 'GetUniqueID', 'Read', 'ReadFromEntity', 'R
eadFromStream', 'RegisterElement', 'SetBase', 'SetLang', 'UnregisterElement', 'Update', 'ValidationEr
ror', 'WriteXML', 'XMLParser', 'bytes', 'class', 'delattr', 'dict', 'dir', 'doc ', 'eq', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'le'
, 'lt', 'module', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr ', 'sizeof', 'str', 'subclasshook', 'unicode', 'weakref__', 'add_child', 'base_uri
', 'create', 'data', 'declaration', 'diff_string', 'dtd', 'generate_xml', 'get_base', 'get_child_clas
s', 'get_children', 'get_element_by_id', 'get_element_class', 'get_lang', 'get_space', 'get_unique_id
', 'idTable', 'lang', 'parent', 'processing_instruction', 'read', 'read_from_entity', 'read_from_stre
am', 'register_element', 'req_manager', 'root', 'set_base', 'set_lang', 'unregister_element', 'update
', 'validation_error', 'write_xml']d.dict
{'parent': None, 'idTable': {}, 'root': <pyslet.xml.structures.Element object at 0x106095240>, 'req_manag
er': None, 'dtd': <pyslet.xml.structures.XMLDTD object at 0x103f40eb8>, 'data': [], 'declaration': None,
'base_uri': <pyslet.rfc2396.FileURL object at 0x103b3cba8>, 'lang': None}
d.root.get_value()
Traceback (most recent call last):
File "<input>", line 1, in <module>
d.root.get_value()
File "/Users/annaliao/repos/pyslet/pyslet/xml/structures.py", line 2335, in get_value
return join_characters(self.generate_value(ignore_elements))
File "/Users/annaliao/repos/pyslet/pyslet/xml/structures.py", line 2305, in generate_value
raise XMLMixedContentError(str(self))
pyslet.xml.structures.XMLMixedContentError:<assessmentItem adaptive="false" identifier="choice" timeDependent="false" title="Unattended Luggage" xml ns="http://www.imsglobal.org/xsd/imsqti_v2p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:s chemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p2 http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v 2p2.xsd"><responseDeclaration baseType="identifier" cardinality="single" identifier="RESPONSE"><correctRe sponse><value>ChoiceA</value></correctResponse></responseDeclaration> <outcomeDeclaration baseType="float " cardinality="single" identifier="SCORE"><defaultValue><value>0</value></defaultValue></outcomeDeclarati on> <itemBody><p>Look at the text in the picture.</p> <p><img alt="NEVER LEAVE LUGGAGE UNATTENDED" src="i mages/sign.png"/></p> <choiceInteraction maxChoices="1" responseIdentifier="RESPONSE" shuffle="false"><pr ompt>What does it say?</prompt> <simpleChoice identifier="ChoiceA">You must stay with your luggage at all
times.</simpleChoice> <simpleChoice identifier="ChoiceB">Do not let someone else look after your luggage
.</simpleChoice> <simpleChoice identifier="ChoiceC">Remember your luggage when you leave.</simpleChoice><
/choiceInteraction></itemBody> <responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/r ptemplates/match_correct"/></assessmentItem>doc
children = list(d.get_children())
len(children)
1
children
[<pyslet.xml.structures.Element object at 0x106095240>]
children[0].xmlname
'assessmentItem'
children[0].get_value()
Traceback (most recent call last):
File "<input>", line 1, in <module>
children[0].get_value()
File "/Users/annaliao/repos/pyslet/pyslet/xml/structures.py", line 2335, in get_value
return join_characters(self.generate_value(ignore_elements))
File "/Users/annaliao/repos/pyslet/pyslet/xml/structures.py", line 2305, in generate_value
raise XMLMixedContentError(str(self))
pyslet.xml.structures.XMLMixedContentError:<assessmentItem adaptive="false" identifier="choice" timeDependent="false" title="Unattended Luggage" xml ns="http://www.imsglobal.org/xsd/imsqti_v2p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:s chemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p2 http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v 2p2.xsd"><responseDeclaration baseType="identifier" cardinality="single" identifier="RESPONSE"><correctRe sponse><value>ChoiceA</value></correctResponse></responseDeclaration> <outcomeDeclaration baseType="float " cardinality="single" identifier="SCORE"><defaultValue><value>0</value></defaultValue></outcomeDeclarati on> <itemBody><p>Look at the text in the picture.</p> <p><img alt="NEVER LEAVE LUGGAGE UNATTENDED" src="i mages/sign.png"/></p> <choiceInteraction maxChoices="1" responseIdentifier="RESPONSE" shuffle="false"><pr ompt>What does it say?</prompt> <simpleChoice identifier="ChoiceA">You must stay with your luggage at all
times.</simpleChoice> <simpleChoice identifier="ChoiceB">Do not let someone else look after your luggage
.</simpleChoice> <simpleChoice identifier="ChoiceC">Remember your luggage when you leave.</simpleChoice><
/choiceInteraction></itemBody> <responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/r ptemplates/match_correct"/></assessmentItem>