Deleting Nodes and trying to use GetDOM - InfoPath Dev
in

InfoPath Dev

Deleting Nodes and trying to use GetDOM

Last post 06-30-2010 10:51 AM by Pinback. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-29-2010 11:35 AM

    Deleting Nodes and trying to use GetDOM

    Hello,

    Very new to InfoPath, thought I should post in Newbies.

     InfoPath 2007
    .net 3.5
    XPath = "/sections/section"
    VB

    I am trying to find a way to Delete nodes in a Secondary Data Source (Resource File). It appears iteration will not work if you are deleting more than one. I am attempting to leverage XDocument.GetDOM, but GetDOM does not appear to be part of my System.Xml.Linq.XDocument. I did a search before I posted and could not find an answer. Any thoughts on GetDOM, and any thoughts on the best way to go about Deleting Nodes from a Resource File set as a Secondary Data Source?

    Thanks in advance!

    Pinback

  • 06-30-2010 01:43 AM In reply to

    Re: Deleting Nodes and trying to use GetDOM

    GetDOM() belongs to Microsoft.Office.Interop.InfoPath.XDocument, not System.Xml.Link.XDocument, and this XDocument is used in the InfoPath 2003 object model.  If you're writing InfoPath 2007 code, this is not available.

    The easiest way to delete a set of nodes in InfoPath 2007 code is probably

    XPathNavigator toDelete;

    while((toDelete = someNode.SelectSingleNode(xpath, NamespaceManager)) != null)
    {
        toDelete.RemoveSelf();
    }

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-30-2010 06:45 AM In reply to

    Re: Deleting Nodes and trying to use GetDOM

    Thanks Jimmy,

    I am trying to convert the above to VB, but I must be missing something:

                Dim Nav As System.Xml.XPath.XPathNavigator
                Dim DNode As System.Xml.XPath.XPathNavigator

                Nav = Me.DataSources("sections").CreateNavigator
    *           Do While (Nav = Node1.SelectSingleNode("/sections/section", Me.NamespaceManager)) <> DBNull.Value
                    Nav.DeleteSelf()
                Loop

    I get an error on the * line telling me: Error 4 Operator '=' is not defined for types 'System.Xml.XPath.XPathNavigator' and 'System.Xml.XmlNode'. 

    Any thoughts? :)

  • 06-30-2010 07:22 AM In reply to

    Re: Deleting Nodes and trying to use GetDOM

    Something more like this should work 

    Dim Nav As System.Xml.XPath.XPathNavigator
    Dim DNode As System.Xml.XPath.XPathNavigator
    Nav =
    Me.DataSources("sections").CreateNavigator

    Do
        DNode = Nav.SelectSingleNode("/sections/section", Me.NamespaceManager)
        If DNode IsNot Nothing Then
            DNode.DeleteSelf()
        End If
    Loop Until DNode Is Nothing

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-30-2010 10:51 AM In reply to

    Re: Deleting Nodes and trying to use GetDOM

    Thank you for your help, Jimmy.

    It looks like your code worked perfectly. Thanks again!

    Pinback

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.