Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB XML DOM
Dim oNode As IXMLDOMNode
 
    For Each oNode In oItemNodes
        Set sPMIDNode = oNode.selectSingleNode("//PMID")
        If Not sPMIDNode Is Nothing Then sPMID = sPMIDNode.Text
        Set sTitleNode = oNode.selectSingleNode("//ArticleTitle")
        If Not STitleNode Is Nothing Then sTitle = STitleNode.Text
        Set SAbstractNode = oNode.selectSingleNode("//AbstractText")
        If Not SAbstractNode Is Nothing Then sAbstract = SAbstractNode.Text
    Next
 

I am having trouble getting the PMID, Article Title, and Abstract Text to line up correctly in a table when there is missing data. I have resorted to the following code, but I just get the first item in the node list repeated. How can I loop through the node list and get text values when they exist and have everything line up in the resulting table?
 
The XML from PubMed sometimes has an abstract and sometimes it does not. The oItemNodes is a node list of PubMed Articles. oNode increments correctly. SelectSingleNode does not work. It just finds the first Article.
Posted 26-Sep-12 13:03pm
tbarrus277
Edited 26-Sep-12 16:36pm
v2
Comments
Sergey Alexandrovich Kryukov at 26-Sep-12 19:38pm
   
What do you mean by "VB"? (And, if this is something like VB6, better don't parse anything. :-)
--SA
tbarrus at 26-Sep-12 22:30pm
   
Something like VB6. A DOM nodelist should work.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try:
Dim oNode As IXMLDOMNode
 
    For Each oNode In oItemNodes
        Set sPMIDNode = oNode.selectSingleNode("/PMID")
        If Not sPMIDNode Is Nothing Then sPMID = sPMIDNode.Text
        Set sTitleNode = oNode.selectSingleNode("/ArticleTitle")
        If Not STitleNode Is Nothing Then sTitle = STitleNode.Text
        Set SAbstractNode = oNode.selectSingleNode("/AbstractText")
        If Not SAbstractNode Is Nothing Then sAbstract = SAbstractNode.Text
    Next
 
ref: http://msdn.microsoft.com/en-us/library/windows/desktop/ms757846(v=vs.85).aspx[^]
  Permalink  
Comments
tbarrus at 26-Sep-12 23:03pm
   
/PMID does not work because it is not a root node. PMID, ArticleTitle, and AbstractText are childnodes of PubMedArticle. Here are the exact XPath for each item:
 
/PubMedArticle/MedlineCitation/PMID
 
/PubMedArticle/MedlineCitation/PMID/Article/ArticleTitle
 
/PubMedArticle/MedlineCitation/PMID/Article/Abstract/AbstractText
Kuthuparakkal at 27-Sep-12 0:34am
   
try
./PPMD
tbarrus at 27-Sep-12 11:54am
   
Thanks for the hint. This worked (./MedlineCitation/PMID)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100