Skip to content
Snippets Groups Projects
Commit 4817ebf9 authored by Kipp Cannon's avatar Kipp Cannon
Browse files

RankingStatPDF: add .get_xml_root() class method

parent c705b696
No related branches found
No related tags found
No related merge requests found
......@@ -766,11 +766,25 @@ WHERE
return health >= 1.
@classmethod
def get_xml_root(cls, xml, name):
"""
Sub-classes can use this in their overrides of the
.from_xml() method to find the root element of the XML
serialization.
"""
name = u"%s:%s" % (name, cls.ligo_lw_name_suffix)
xml = [elem for elem in xml.getElementsByTagName(ligolw.LIGO_LW.tagName) if elem.hasAttribute(u"Name") and elem.Name == name]
if len(xml) != 1:
raise ValueError("XML tree must contain exactly one %s element named %s" % (ligolw.LIGO_LW.tagName, name))
return xml[0]
@classmethod
def from_xml(cls, xml, name):
# find the root of the XML tree containing the
# serialization of this object
xml, = [elem for elem in xml.getElementsByTagName(ligolw.LIGO_LW.tagName) if elem.hasAttribute(u"Name") and elem.Name == u"%s:%s" % (name, cls.ligo_lw_name_suffix)]
xml = cls.get_xml_root(xml, name)
# create a mostly uninitialized instance
self = cls(None)
# populate from XML
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment