Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing an XML child node 1

Status
Not open for further replies.

BG12424

Programmer
Joined
Jun 4, 2002
Messages
717
Location
US
I am having a problem removing my <UserInfo> child node from this XML format. Can anyone please provide any suggestions? Thanks

Code:
<?xml version="1.0"?>
<Locks>
  <Filing FormType="FRI" FilingType="R" EndDate="1/1/2005" FirmId="0000173">
    <UserInfo UserId="nfisbjg" Session="kvoyaz550ceqifm3btr5aoaf" />
    <UserInfo UserId="nfisbjg" Session="234kjosdfoowaef" />
</Filing>
</Locks>
Code:
Public Sub DeleteUserFromFiling()

    Dim xmlDocument As XmlDocument
    xmlDocument = LoadXmlFile()

    If ( Not xmlDocument Is Nothing ) Then        

        Dim xPathQuery As String 
        xPathQuery = "//Locks/Filing/UserInfo[@Session='" & m_SessionId & "']"

        Dim xmlNode As XmlNode
        xmlNode = xmlDocument.SelectSingleNode(xPathQuery)
'--------- PROBLEM IS HERE ------------
        xmlDocument.DocumentElement.RemoveChild(xmlNode)
        xmlDocument.RemoveChild(xmlNode)

        Dim parentNode As XmlNode
        parentNode = FindFilingByUserId(xmlDocument)
        
        'Only remove the filing element if there are not any additional
        'user session information appended as children to the filing element.
        'This enables the filing to still be active when multiple browser
        'sessions are timing out causing this routine to be called.
        If parentNode.HasChildNodes = False Then
            parentNode.RemoveAll()
        End If

        xmlDocument.Save(m_XmlFile)

    End If

End Sub

regards,
Brian
The problem with doing something right the first time is that nobody appreciates how difficult it was.
 
xmlDocument.DocumentElement.RemoveChild(xmlNode):
but your xmlNode is not a child of the document element.

Try something like:
xmlNode.parentNode.removeChild xmlNode
 
Thank you, this resolved my problem. I actually took a slightly different approach, but this helped.

regards,
Brian
The problem with doing something right the first time is that nobody appreciates how difficult it was.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top