Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
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
Updated 26-Sep-12 16:36pm
v2
Comments
Sergey Alexandrovich Kryukov 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 26-Sep-12 22:30pm    
Something like VB6. A DOM nodelist should work.

1 solution

try:
SQL
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[^]
 
Share this answer
 
Comments
tbarrus 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 27-Sep-12 0:34am    
try
./PPMD
tbarrus 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900