Code:
# Example of using the provided stream based QuickParser
# to parse metadataxml (to look for cover id)
# Also rebuilds the metadata xml in res
ps = bk.qp
ps.setContent(bk.getmetadataxml())
res = []
coverid = None
# parse the metadataxml, store away cover_id and rebuild it
for text, tagprefix, tagname, tagtype, tagattr in ps.parse_iter():
if text is not None:
# print(text)
res.append(text)
else:
# print(tagprefix, tagname, tagtype, tagattr)
if tagname == "meta" and tagattr.get("name",'') == "cover":
coverid = tagattr["content"]
res.append(ps.tag_info_to_xml(tagname, tagtype, tagattr))
original_metadata = "".join(res)