def writeXML(self, filename): """ write abstract out to xml file with given filename """ print 'Writing:', filename doc = xml.dom.minidom.Document() node = self.getXML(doc) out = open(filename, 'w') out.write('<?xml version="1.0" encoding="utf-8"?>\n') out.write('<?xml-stylesheet href="http://www.andrews.edu/~summersc/abstract.xsl" type="text/xsl"?>\n') xmlutil.writexml(node, out) out.close()
def writeXML(self, filename): """ write abstract out to xml file with given filename """ print 'Writing:', filename doc = xml.dom.minidom.Document() node = self.getXML(doc) out = open(filename, 'w') out.write('<?xml version="1.0" encoding="utf-8"?>\n') out.write( '<?xml-stylesheet href="http://www.andrews.edu/~summersc/abstract.xsl" type="text/xsl"?>\n' ) xmlutil.writexml(node, out) out.close()
def writeXML(self, path, version): """ Write summary to XML file in the destination directory specified by path. """ idPrefix = self.abstract.id + 'v' + version # build XML summary doc = xml.dom.minidom.Document() articleNode = doc.createElement('Study') if self.randomized: articleNode.setAttribute('RandomizationPresent', 'true') else: articleNode.setAttribute('RandomizationPresent', 'false') articleNode.setAttribute('Version', version) gmTime = time.gmtime() cNode = doc.createElement('Created') articleNode.appendChild(cNode) cNode.appendChild(xmlutil.createNodeWithTextChild(doc, 'Month', str(gmTime.tm_mon))) cNode.appendChild(xmlutil.createNodeWithTextChild(doc, 'Day', str(gmTime.tm_mday))) cNode.appendChild(xmlutil.createNodeWithTextChild(doc, 'Year', str(gmTime.tm_year))) nameNode = xmlutil.createNodeWithTextChild(doc, 'Name', self.abstract.id) articleNode.appendChild(nameNode) titleString = '' for s in self.abstract.titleSentences: titleString += s.toString() titleNode = xmlutil.createNodeWithTextChild(doc, 'Title', titleString) articleNode.appendChild(titleNode) link = 'http://www.ncbi.nlm.nih.gov/pubmed/' + self.abstract.id linkNode = xmlutil.createNodeWithTextChild(doc, 'AbstractLink', link) articleNode.appendChild(linkNode) if self.abstract.report is not None and self.abstract.report.id[0:3] == 'NCT': link = 'http://clinicaltrials.gov/ct2/show/study/' + self.abstract.report.id linkNode = xmlutil.createNodeWithTextChild(doc, 'TrialRegistryLink', link) articleNode.appendChild(linkNode) node = self.locationList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) if self.useTrialReports and self.abstract.report is not None \ and len(self.abstract.report.conditions) > 0: cListNode = doc.createElement('ConditionsOfInterest') articleNode.appendChild(cListNode) for condition in self.abstract.report.conditions: cNode = doc.createElement('Condition') cNode.appendChild(xmlutil.createNodeWithTextChild(doc, 'Name', condition.sentences[0].toString())) cNode.setAttribute('source', 'trial_registry') cListNode.appendChild(cNode) node = self.subjectList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) node = self.outcomeList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) if self.abstract.meshHeadingList is not None: articleNode.appendChild(self.abstract.meshHeadingList.getXML(doc)) htmlString = StringIO.StringIO() self.writeHTML(htmlString, showError=False) htmlNode = xmlutil.createNodeWithTextChild(doc, 'HTMLData', htmlString.getvalue()) articleNode.appendChild(htmlNode) htmlString.close() # write summary to XML file filename = path + self.abstract.id + '.summary.xml' out = open(filename, 'w') out.write('<?xml version="1.0" encoding="utf-8"?>\n') # out.write('<?xml-stylesheet href="abstract.xsl" type="text/xsl"?>\n') xmlutil.writexml(articleNode, out) out.close()
def writeXML(self, path, version): """ Write summary to XML file in the destination directory specified by path. """ idPrefix = self.abstract.id + 'v' + version # build XML summary doc = xml.dom.minidom.Document() articleNode = doc.createElement('Study') if self.randomized: articleNode.setAttribute('RandomizationPresent', 'true') else: articleNode.setAttribute('RandomizationPresent', 'false') articleNode.setAttribute('Version', version) gmTime = time.gmtime() cNode = doc.createElement('Created') articleNode.appendChild(cNode) cNode.appendChild( xmlutil.createNodeWithTextChild(doc, 'Month', str(gmTime.tm_mon))) cNode.appendChild( xmlutil.createNodeWithTextChild(doc, 'Day', str(gmTime.tm_mday))) cNode.appendChild( xmlutil.createNodeWithTextChild(doc, 'Year', str(gmTime.tm_year))) nameNode = xmlutil.createNodeWithTextChild(doc, 'Name', self.abstract.id) articleNode.appendChild(nameNode) titleString = '' for s in self.abstract.titleSentences: titleString += s.toString() titleNode = xmlutil.createNodeWithTextChild(doc, 'Title', titleString) articleNode.appendChild(titleNode) link = 'http://www.ncbi.nlm.nih.gov/pubmed/' + self.abstract.id linkNode = xmlutil.createNodeWithTextChild(doc, 'AbstractLink', link) articleNode.appendChild(linkNode) if self.abstract.report is not None and self.abstract.report.id[ 0:3] == 'NCT': link = 'http://clinicaltrials.gov/ct2/show/study/' + self.abstract.report.id linkNode = xmlutil.createNodeWithTextChild(doc, 'TrialRegistryLink', link) articleNode.appendChild(linkNode) node = self.locationList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) if self.useTrialReports and self.abstract.report is not None \ and len(self.abstract.report.conditions) > 0: cListNode = doc.createElement('ConditionsOfInterest') articleNode.appendChild(cListNode) for condition in self.abstract.report.conditions: cNode = doc.createElement('Condition') cNode.appendChild( xmlutil.createNodeWithTextChild( doc, 'Name', condition.sentences[0].toString())) cNode.setAttribute('source', 'trial_registry') cListNode.appendChild(cNode) node = self.subjectList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) node = self.outcomeList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) if self.abstract.meshHeadingList is not None: articleNode.appendChild(self.abstract.meshHeadingList.getXML(doc)) htmlString = StringIO.StringIO() self.writeHTML(htmlString, showError=False) htmlNode = xmlutil.createNodeWithTextChild(doc, 'HTMLData', htmlString.getvalue()) articleNode.appendChild(htmlNode) htmlString.close() # write summary to XML file filename = path + self.abstract.id + '.summary.xml' out = open(filename, 'w') out.write('<?xml version="1.0" encoding="utf-8"?>\n') # out.write('<?xml-stylesheet href="abstract.xsl" type="text/xsl"?>\n') xmlutil.writexml(articleNode, out) out.close()