+def read_musicxml (filename, compressed, use_lxml):
+ raw_string = None
+ if compressed:
+ progress ("Input file %s is compressed, extracting raw MusicXML data" % filename)
+ z = zipfile.ZipFile (filename, "r")
+ container_xml = z.read ("META-INF/container.xml")
+ if not container_xml:
+ return None
+ container = read_xml (StringIO.StringIO (container_xml), use_lxml)
+ if not container:
+ return None
+ rootfiles = container.get_maybe_exist_named_child ('rootfiles')
+ if not rootfiles:
+ return None
+ rootfile_list = rootfiles.get_named_children ('rootfile')
+ mxml_file = None
+ if len (rootfile_list) > 0:
+ mxml_file = getattr (rootfile_list[0], 'full-path', None)
+ if mxml_file:
+ raw_string = z.read (mxml_file)
+
+ io_object = filename
+ if raw_string:
+ io_object = StringIO.StringIO (raw_string)
+
+ return read_xml (io_object, use_lxml)
+
+