+ Reply to Thread
Results 1 to 2 of 2

Thread: Remove elements from DOMSelection

  1. #1
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    XP 2003
    Posts
    182

    Remove elements from DOMSelection

    Hi,
    I have a DOMSelection and I need to cycle through it and remove some nodes. The resulting DOMSelection will be used somewhere else. How can I achieve this?

    I have tried to use the .removeChild method. This DO remove the node from the main XML document, but the original DOMSelection stays with the childnode in it.

    This is the procedure that I use right now.
    This procedure does nothing more than adjusting the amount of childs a given Node should have.
    Private Sub SizeXmlNode(ActXpath As String, NrOfChilds As Long)
        Dim NodeList As MSXML2.IXMLDOMSelection
        Dim tNode As MSXML2.IXMLDOMNode
        'glbXmlDoc is a xml Document (MSXML2.DOMDocument60)
    
        Set NodeList = glbXmlDoc.SelectNodes(ActXpath)
        
        'If the xmlNode is too big, then trim the xml
        If NodeList.Length > NrOfChilds Then
            Do
                NodeList.Item(0).ParentNode.RemoveChild NodeList.Item(0)
            Loop Until glbXmlDoc.SelectNodes(ActXpath).Length = NrOfChilds
            
        End If
    End Sub
    '
    Another problem I have is that the line
     NodeList.Item(0).ParentNode.RemoveChild NodeList.Item(0)
    will work only one time. After the second pass, it pops a "Object variable or With block variable not set"

    Every help is very appreciated. Thanks!
    Last edited by Wizz; 05-03-2011 at 09:12 AM. Reason: Adding more info

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    245

    Re: Remove elements from DOMSelection

    Try putting the Set NodeList inside the loop as well.

    Also, your If ... Loop Until structure tells me that a While loop is more suitable.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0