I'm have a tough time getting the value for a particular node. I'm pulling my XML data from the url http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=25092882,25260646,25242549&retmode=xml and I'm using the following code
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
myFunction(xhttp);
}
};
xhttp.open("GET",
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=25092882,25260646,25242549&retmode=xml",
true);
xhttp.send();}
function myFunction(xml) {
var txt = '';
var i;
var affiliation;
var aff;
var pmcid = '';
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("PubmedArticle");
var authors = "";
for (i = 0; i < x.length; i++) {
var pmid = 'PMID: ' + x[i].getElementsByTagName("PMID")[0].childNodes[
0].nodeValue;
txt += pmid + "</br> ";
var author = x[i].getElementsByTagName("Author");
for (a = 0; a < author.length; a++) {
authors += author[a].getElementsByTagName("LastName")[0].childNodes[
0].nodeValue;
authors += " ";
authors += author[a].getElementsByTagName("Initials")[0].childNodes[
0].nodeValue;
affiliation = author[a].getElementsByTagName("AffiliationInfo")
authors += " Author Affiliation: " + affiliation[0].getElementsByTagName(
"Affiliation")[0].childNodes[0].nodeValue;
authors += " " + "</br> ";
}
txt += authors + " ";
var articleTitle = 'Article Title: ' + x[i].getElementsByTagName(
"ArticleTitle")[0].childNodes[0].nodeValue;
txt += articleTitle + "</br> ";
var journal = 'Journal Title: ' + x[i].getElementsByTagName("Title")[
0].childNodes[0].nodeValue;
txt += journal + "</br> ";
var yearPub = 'Date Published: ';
txt += yearPub + "</br> "
var AbstractText = 'Abstract Text: ' + x[i].getElementsByTagName(
"AbstractText")[0].childNodes[0].nodeValue;
txt += AbstractText + "</br> ";
txt += "PMCID: " + pmcid + "</br> "
txt += "</br> "
}
document.getElementById("demo").innerHTML += txt;
}
The line I'm having trouble with is the affiliation. The value is inside the Author Node that I'm looping and then there is the AffiliationInfo then Affiliation. If I take the Affiliation information out the function runs fine but I need to get the Affiliation values.
Thanks ahead of time.