def to_xml(self, dom): # TODO: Return error codes instead? assert self.note_record_id is not None and \ self.author_name is not None pxml = dom.createElementNS(PFIF_13_NS, "note") for attr in PFIF_13_NOTE_ATTRS: if getattr(self, attr) is not None: add_string_element(dom, pxml, PFIF_13_NS, attr, getattr(self, attr)) return pxml
def add_string_element(dom, xmlnode, ns, name, data, attributes=()): if ns: e = dom.createElementNS(ns, name) else: e = dom.createElement(name) e.appendChild(dom.createTextNode(data)) for (attr_name, attr_value) in attributes: e.setAttribute(attr_name, attr_value) xmlnode.appendChild(e)
def create_text_element(dom, ns, name, data, attributes=()): if ns: e = dom.createElementNS(ns, name) else: e = dom.createElement(name) e.appendChild(dom.createTextNode(data)) for (attr_name, attr_value) in attributes: e.setAttribute(attr_name, attr_value) return e
def add_string_element(dom, xmlnode, ns, name, data, attributes=()): if ns: e = dom.createElementNS(ns, name) else: e = dom.createElement(name) e.appendChild(dom.createTextNode(data)) for (attr_name, attr_value) in attributes: e.setAttribute(attr_name, attr_value) xmlnode.appendChild(e)
def to_xml(self, dom): # TODO: Return error codes instead? assert self.person_record_id is not None and \ self.first_name is not None and \ self.last_name is not None pxml = dom.createElementNS(PFIF_13_NS, "person") for attr in PFIF_13_PERSON_ATTRS: if getattr(self, attr) is not None: add_string_element(dom, pxml, PFIF_13_NS, attr, getattr(self, attr)) for note in self.notes: pxml.appendChild(note.to_xml(dom)) return pxml