]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Fix using lxml as XML parser
authorReinhold Kainhofer <reinhold@kainhofer.com>
Mon, 25 Feb 2008 12:14:25 +0000 (13:14 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Mon, 25 Feb 2008 12:14:25 +0000 (13:14 +0100)
Unfortunately, the default lxml.etree parser also includes comments
in its tree, which does not return a string as its tag, but a built-in
function Comment. Thus, I need to filter out all these comments.
It seems that lxml does not have any convenient way to check whether
a given node is a comment, so I convert it to its string representation
and compare with "<!--.*-->". Of course, this is a bad hack, but I haven't
found a better way yet.

python/musicxml.py

index f028cce8a3a50c8d531040f6b0683f97e26eb030..e9d1ef8bedebd195450a78660f3ff716379dbc5e 100644 (file)
@@ -953,7 +953,9 @@ def get_class (name):
 def lxml_demarshal_node (node):
     name = node.tag
 
-    if name is None:
+    # TODO: This is a nasty hack, but I couldn't find any other way to check
+    #       if the given node is a comment node (class _Comment):
+    if name is None or re.match (u"^<!--.*-->$", node.__repr__()):
         return None
     klass = get_class (name)
     py_node = klass()