Created
April 23, 2019 19:28
-
-
Save lindenb/a5a8fa1b8e3c855917235df347f20f44 to your computer and use it in GitHub Desktop.
https://www.biostars.org/p/376339/ pubmed xpath xml java unitprot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.*; | |
import java.util.*; | |
import java.io.*; | |
import org.w3c.dom.*; | |
import javax.xml.xpath.*; | |
import javax.xml.parsers.*; | |
public class Biostar376339 { | |
public static void main(final String args[]) { | |
try { | |
String urlstr="https://www.uniprot.org/uniprot/P0AD86.xml"; | |
DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance(); | |
factory.setNamespaceAware(true); | |
DocumentBuilder builder = factory.newDocumentBuilder(); | |
Document dom = builder.parse(urlstr); | |
XPathFactory xpathfactory = XPathFactory.newInstance(); | |
XPath xpath = xpathfactory.newXPath(); | |
XPathExpression expr = xpath.compile("//*[local-name()='dbReference' and @type='PubMed']/@id"); | |
XPathExpression expr2 = xpath.compile("/PubmedArticleSet/PubmedArticle/MedlineCitation/Article/ArticleTitle"); | |
NodeList nodes = (NodeList)expr.evaluate(dom, XPathConstants.NODESET); | |
for (int i = 0; i < nodes.getLength(); i++) { | |
final String pmid=nodes.item(i).getNodeValue(); | |
Document dom2 = builder.parse("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?retmode=xml&db=pubmed&id="+pmid); | |
System.out.println(pmid+" "+expr2.evaluate(dom2, XPathConstants.STRING)); | |
} | |
} | |
catch(Exception err) { | |
err.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment