CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2004
    Location
    Israel
    Posts
    174

    MSXML2.DOMDocument30 and xml

    i am parsing an XML using MSXML2.DOMDocument40
    (almost everything is written)
    but i look for a way how can i check if a certain node dosent exist
    when i try to access by "getElementsByTagName" like this :
    PHP Code:
    objXMLDOM.getElementsByTagName("xxx"
    how can i check if a node exist or not so i wont get an error ?
    thnaks in advance
    peleg

  2. #2
    Join Date
    Feb 2003
    Location
    AR
    Posts
    228

    Re: MSXML2.DOMDocument30 and xml

    Since getElementsByTagName returns a list of nodes, simply check for the length property this way:

    Code:
    Dim xNodeList   As IXMLDOMNodeList
    
    Set xNodeList = xDoc.getElementsByTagName("MyNode")  'returns list of nodes with this name
    
    MsgBox xNodeList.length '0 if no matches
    where xDoc is your MSXML.DOMDocument variable.

    Check out this URL for more info, that's where I'm learning MSXML basics.

    http://www.thescarms.com/XML/DOMTutorial.asp

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: MSXML2.DOMDocument30 and xml

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Feb 2003
    Location
    AR
    Posts
    228

    Re: MSXML2.DOMDocument30 and xml

    Quote Originally Posted by dglienna
    Actually that's for HTML only... the XML section at MSDN can be found here:

    http://msdn.microsoft.com/library/de...aa453bfde1.asp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured