by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Anna Liao
    @anna-liao
    Think validation should come after the parser is working for well-formed and valid types
    John Vandenberg
    @jayvdb
    I think we were planning on having another voice chat today-ish. Im back in Indonesia, and it is 11pm, but I am online for another few hours
    Anna Liao
    @anna-liao
    oh ok
    So I re-wrote the parser
    and it handles more question types
    I'm thinking about adding feedback nested in a *Response element
    But I'm not sure how to do that
    Also working on reading in a document
    Previously, I instantiate an Element and then add children to that Element
    Usually the document root is an Element
    however, adding a child to the document, is replacing the document root
    which is strange. This is why when I parse a GIFT format text from a file, it only shows the last element
    I still don't understand why it is defined as such in Pyslet
    And there is also adding validation
    John Vandenberg
    @jayvdb
    in XML, the document root is a special node which contains all the other nodes, directly or indirectly.
    it will include things like the preamble , which isnt a typical element.
    Anna Liao
    @anna-liao
    I would have thought it would make sense when adding a child element to the document root, it would be adding a child to the document root Element. However, it seems that it replaces it.
    There is just a few ways to go
    I could work on reading in a file
    work on adding more supported types
    or work on validation
    John Vandenberg
    @jayvdb
    can you print out a 'tree' of a parsed QTI document ?
    Anna Liao
    @anna-liao
    Hmm, I guess I could try that
    I could just run the QTI sample and see what it looks like
    John Vandenberg
    @jayvdb
    so we can see which classes are used at which levels of the tree of an QTI object
    Anna Liao
    @anna-liao
    ok, I will look into it
    Anna Liao
    @anna-liao
    hmm, ok, after running a QTI example through the document read
    it does look like all the elements are lumped together into one string
    it is just the header in one string and all the other elements in the other string

    dlines=[b'<?xml version="1.0" encoding="UTF-8"?>', b'<assessmentItem adaptive="false" identifier="cho ice" timeDependent="false" title="Unattended Luggage" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2 " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/ xsd/imsqti_v2p2 http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2.xsd"><responseDeclaration baseTy pe="identifier" cardinality="single" identifier="RESPONSE"><correctResponse><value>ChoiceA</value></c orrectResponse></responseDeclaration> <outcomeDeclaration baseType="float" cardinality="single" ident ifier="SCORE"><defaultValue><value>0</value></defaultValue></outcomeDeclaration> <itemBody><p>Look at
    the text in the picture.</p> <p><img alt="NEVER LEAVE LUGGAGE UNATTENDED" src="images/sign.png"/></p

    <choiceInteraction maxChoices="1" responseIdentifier="RESPONSE" shuffle="false"><prompt>What does i
    t say?</prompt> <simpleChoice identifier="ChoiceA">You must stay with your luggage at all times.</sim pleChoice> <simpleChoice identifier="ChoiceB">Do not let someone else look after your luggage.</simpl eChoice> <simpleChoice identifier="ChoiceC">Remember your luggage when you leave.</simpleChoice></cho iceInteraction></itemBody> <responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/r ptemplates/match_correct"/></assessmentItem>']

    len(dlines)
    2
    that's good then
    that's what my code does now
    it just lumps all the elements together in one string
    so it is different from how it worked with just an Element.
    d = structures.Document(base_uri='choice.xml')
    d.read()
    dlines = bytes(d).split(b'\n')
    ok, I guess I will leave it as is
    looks like for a document root, it just lumps all the elements into a single string. seems a bit odd
    That was taken from this unittest
    John Vandenberg
    @jayvdb
    instead of doing it in a unit test, try it in the python console. soemthing like
    $ 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()
    (replacing ... in the path with the location of the data dir)
    then you can look at d in more detail
    bytes(d) doesnt tell you much -- that almost certainly re-serialises d into a bytestream
    instead, do type(d), and dir(d) to look at the d object type, and what attributes it has that can be explored
    Anna Liao
    @anna-liao
    I ran it in a console, not in a unittest
    sure, i will check the type
    Anna Liao
    @anna-liao

    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>