From fdf984d07de7f5cdc8e81b97c8c28a2c39e07b34 Mon Sep 17 00:00:00 2001 From: ThunderEX Date: Wed, 24 May 2017 21:08:30 +0800 Subject: [PATCH] xmltok: Skip comment markup in XML. This is provisional solution, at later time, comments may become tokenized and fed to the caller, like other syntactic elements. --- xmltok/test.xml | 1 + xmltok/xmltok.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/xmltok/test.xml b/xmltok/test.xml index 1c3607f1..e13f548c 100644 --- a/xmltok/test.xml +++ b/xmltok/test.xml @@ -9,5 +9,6 @@ baz + diff --git a/xmltok/xmltok.py b/xmltok/xmltok.py index c7143787..c46f2bd4 100644 --- a/xmltok/xmltok.py +++ b/xmltok/xmltok.py @@ -95,6 +95,14 @@ class XMLTokenizer: yield from self.lex_attrs_till() self.expect("?") self.expect(">") + elif self.match("!"): + self.expect("-") + self.expect("-") + last3 = '' + while True: + last3 = last3[-2:] + self.getch() + if last3 == "-->": + break else: tag = self.getnsident() yield (START_TAG, tag)