def parse_xml(sentence, tab="<STR_LIT:\t>", id="<STR_LIT>"):
uid  = lambda *parts: "<STR_LIT>".join([str(id), _UID_SEPARATOR ]+[str(x) for x in parts]).lstrip(_UID_SEPARATOR)<EOL>push = lambda indent: indent+tab         <EOL>pop  = lambda indent: indent[:-len(tab)] <EOL>indent = tab<EOL>xml = []<EOL>xml.append('<STR_LIT>' % (<EOL>XML_SENTENCE,<EOL>XML_ID and "<STR_LIT>" % (XML_ID, str(id)) or "<STR_LIT>",<EOL>XML_TOKEN, "<STR_LIT:U+002CU+0020>".join(sentence.token),<EOL>XML_LANGUAGE, sentence.language<EOL>))<EOL>anchors = {}<EOL>for chunk in sentence.chunks:<EOL><INDENT>if chunk.attachments:<EOL><INDENT>anchors[chunk.start] = len(anchors) + <NUM_LIT:1><EOL><DEDENT><DEDENT>for word in sentence.words:<EOL><INDENT>chunk = word.chunk<EOL>pnp   = word.chunk and word.chunk.pnp or None<EOL>if pnp and pnp.start == chunk.start:<EOL><INDENT>a = pnp.anchor and '<STR_LIT>' % (XML_OF, uid("<STR_LIT:A>", anchors.get(pnp.anchor.start, "<STR_LIT>"))) or "<STR_LIT>"<EOL>xml.append(indent + '<STR_LIT>' % (XML_CHUNK, XML_TYPE, a))<EOL>indent = push(indent)<EOL><DEDENT>if chunk and chunk.start == word.index:<EOL><INDENT>if chunk.relations:<EOL><INDENT>r1 = unzip(<NUM_LIT:0>, chunk.relations) <EOL>r2 = unzip(<NUM_LIT:1>, chunk.relations) <EOL>r1 = [x is None and "<STR_LIT:->" or uid(x) for x in r1]<EOL>r2 = [x is None and "<STR_LIT:->" or x for x in r2]<EOL>r1 = not len(unique(r1)) == <NUM_LIT:1> and "<STR_LIT:|>".join(r1) or (r1+[None])[<NUM_LIT:0>]<EOL>r2 = not len(unique(r2)) == <NUM_LIT:1> and "<STR_LIT:|>".join(r2) or (r2+[None])[<NUM_LIT:0>]<EOL><DEDENT>xml.append(indent + '<STR_LIT>' % (<EOL>XML_CHUNK,<EOL>chunk.type and '<STR_LIT>' % (XML_TYPE, chunk.type) or "<STR_LIT>",<EOL>chunk.relations and chunk.role != None and '<STR_LIT>' % (XML_RELATION, r2) or "<STR_LIT>",<EOL>chunk.relation  and chunk.type == "<STR_LIT>" and '<STR_LIT>' % (XML_ID, uid(chunk.relation)) or "<STR_LIT>",<EOL>chunk.relation  and chunk.type != "<STR_LIT>" and '<STR_LIT>' % (XML_OF, r1) or "<STR_LIT>",<EOL>chunk.attachments and '<STR_LIT>' % (XML_ANCHOR, uid("<STR_LIT:A>",anchors[chunk.start])) or "<STR_LIT>"<EOL>))<EOL>indent = push(indent)<EOL><DEDENT>if not chunk:<EOL><INDENT>xml.append(indent + '<STR_LIT>' % XML_CHINK)<EOL>indent = push(indent)<EOL><DEDENT>xml.append(indent + '<STR_LIT>' % (<EOL>XML_WORD,<EOL>word.type and '<STR_LIT>' % (XML_TYPE, xml_encode(word.type)) or '<STR_LIT>',<EOL>word.lemma and '<STR_LIT>' % (XML_LEMMA, xml_encode(word.lemma)) or '<STR_LIT>',<EOL>("<STR_LIT:U+0020>"+"<STR_LIT:U+0020>".join(['<STR_LIT>' % (k,v) for k,v in word.custom_tags.items() if v != None])).rstrip(),<EOL>xml_encode(unicode(word)),<EOL>XML_WORD<EOL>))<EOL>if not chunk:<EOL><INDENT>indent = pop(indent); xml.append(indent + "<STR_LIT>" % XML_CHINK)<EOL><DEDENT>if chunk and chunk.stop-<NUM_LIT:1> == word.index:<EOL><INDENT>indent = pop(indent); xml.append(indent + "<STR_LIT>" % XML_CHUNK)<EOL><DEDENT>if pnp and pnp.stop-<NUM_LIT:1> == word.index:<EOL><INDENT>indent = pop(indent); xml.append(indent + "<STR_LIT>" % XML_CHUNK)<EOL><DEDENT><DEDENT>xml.append("<STR_LIT>" % XML_SENTENCE)<EOL>return "<STR_LIT:\n>".join(xml).encode("<STR_LIT:utf-8>")<EOL>
Returns the given Sentence object as an XML-string (plain bytestring, UTF-8 encoded).
        The tab delimiter is used as indendation for nested elements.
        The id can be used as a unique identifier per sentence for chunk id's and anchors.
        For example: "I eat pizza with a fork." =>

        <sentence token="word, part-of-speech, chunk, preposition, relation, anchor, lemma" language="en">
            <chunk type="NP" relation="SBJ" of="1">
                <word type="PRP" lemma="i">I</word>
            </chunk>
            <chunk type="VP" relation="VP" id="1" anchor="A1">
                <word type="VBP" lemma="eat">eat</word>
            </chunk>
            <chunk type="NP" relation="OBJ" of="1">
                <word type="NN" lemma="pizza">pizza</word>
            </chunk>
            <chunk type="PNP" of="A1">
                <chunk type="PP">
                    <word type="IN" lemma="with">with</word>
                </chunk>
                <chunk type="NP">
                    <word type="DT" lemma="a">a</word>
                    <word type="NN" lemma="fork">fork</word>
                </chunk>
            </chunk>
            <chink>
                <word type="." lemma=".">.</word>
            </chink>
        </sentence>