Parse XML | Cloud systems
Anonymous User
3419

Implement parse()

# public XMLDocument parse(Tokenizer tokenizer) {
#   // TODO: Implement this.
# }
# 
# <a>
#   <b>
#     <c>foo</c>
#     <c></c>
#   </b>
#   <d>blah</d>
# </a>
# 
# Some entities:
# - <root>
#    <child1>
#        <subchild>...</subchild>
#    <child2>
    

class XMLDocument:
    def __init__(self, root: XMLNode):
        self.root = root

Given these interfaces:

# 
# interface Tokenizer {
#   Token nextToken();
# }
# 
# interface Token {
#   String value();
#   TokenType type();
# }
# 
# enum TokenType {
#   BEGIN,
#   END,
#   TEXT,
# }
# 
# * Each call to tokenzer.nextToken() returns:
#  * {
#  *   value: 'a',
#  *   type: 'BEGIN'
#  * }
#  * {
#  *   value: 'b',
#  *   type: 'BEGIN'
#  * }
#  * {
#  *   value: 'c',
#  *   type: 'BEGIN'
#  * }
#  * {
#  *   value: 'foo',
#  *   type: 'TEXT'
#  * }
#  * {
#  *   value: 'c',
#  *   type: 'END'
#  * }
#  * {
#  *   value: 'c',
#  *   type: 'BEGIN'
#  * }
#  * {
#  *   value: 'c',
#  *   type: 'END'
#  * }
#  * {
#  *   value: 'b',
#  *   type: 'END'
#  * }
#  * {
#  *   value: 'd',
#  *   type: 'BEGIN'
#  * }
#  * {
#  *   value: 'blah',
#  *   type: 'TEXT'
#  * }
#  * {
#  *   value: 'd',
#  *   type: 'END'
#  * }
#  * {
#  *   value: 'a',
#  *   type: 'END'
#  * }
# 

Hints given: Creating tree with stack, but not much luck solving it :(

Comments (2)