Right now my app pulls all of the Pubmed IDS from an XML file and displays them in a listbox. That code works fine. I am trying to add a function so when the user clicks the listbox, it searches the XML file for that pubmed ID and grabs the information for the corresponding article. This is where I am running into trouble. I can either get it to grab just the pubmed ID node and nothing else, or i can get it to grab the entirety of the XML file.
I need to retrieve the publication date, the first name, last name, and initial of all the authors in <AuthorList></AuthorList>, and the title of the publication.
This is the code I am trying now.
listBox2.Items.Clear();
//Search the Entrez XML File for the required Data
var xml = XDocument.Load(XMLFileLocal);
var pmidPath = xml.XPathSelectElements(String.Format("/PubmedArticleSet/PubmedArticle/MedlineCitation/PMID[.={0}]", listBox1.SelectedItem.ToString()));
var article = pmidPath.AncestorsAndSelf();
foreach(var author in article.Descendants("AuthorList"))
{
foreach (var subauthor in author.Descendants("Author"))
{
if (subauthor.Element("LastName") != null)
{
authname = subauthor.Element("LastName").Value + ", " + subauthor.Element("ForeName").Value;
}
if ((subauthor.Element("Initials") != null))
{
authname += " " + subauthor.Element("Initials").Value;
}
listBox2.Items.Add(authname);
}
}It pulls the names and constructs the strings just fine, But I only want it to grab the information from the article corresponding to the pubmed ID.
What am I doing wrong here?