Remove node in a view xml 
Author Message
 Remove node in a view xml

hi,

It's still me :)
Pardon.
How can you find a particular node and remove it?
I want to erase all node "orderby" and his child in a view
xml but it's possible?

Why? because i want to change the previous sort and the
previus order must be erase to success.

Thanks



Tue, 12 Oct 2004 23:06:42 GMT  
 Remove node in a view xml
This is the code I use to remove a <column> node. You should be able to adapt it. If I remember right, there is only one <orderby> node, so you should be able to use the SelectSingleNode method. (Columns are more complicated, because there are lots of them.)

Sub RemoveColumn(ByVal objView As Outlook.View, _
                 ByVal strProp As String)
    Dim objXML As New MSXML2.DOMDocument
    Dim objXMLRoot As MSXML2.IXMLDOMNode
    Dim colXMLColNodes As MSXML2.IXMLDOMNodeList
    Dim objXMLColNode As MSXML2.IXMLDOMNode
    On Error Resume Next

    ' load view schema into MSXML parser
    objXML.loadXML objView.XML
    ' get root node ("view")
    Set objXMLRoot = objXML.documentElement

    ' walk tree to find the column
    Set colXMLColNodes = objXMLRoot.selectNodes("column")
    ' try to get column by name
    Set objXMLColNode = GetColumn(colXMLColNodes, strProp)

    ' remove column if found
    If Not objXMLColNode Is Nothing Then
        objXMLRoot.removeChild objXMLColNode
    End If

    ' copy XML back to view and save
    objView.XML = objXML.XML
    objView.Save

    Set objXML = Nothing
    Set objXMLRoot = Nothing
    Set colXMLColNodes = Nothing
    Set objXMLColNode = Nothing
End Sub

Function GetColumn(colColumnNodes As MSXML2.IXMLDOMNodeList, _
        strHeading As String) As MSXML2.IXMLDOMNode
    Dim intIndex As Integer
    Dim objNode As MSXML2.IXMLDOMNode
    Dim objHeadingNode As MSXML2.IXMLDOMNode
    On Error Resume Next

    Set objNode = colColumnNodes.Item(0)
    Do
        Set objHeadingNode = objNode.selectSingleNode("heading")
        If Not objHeadingNode Is Nothing Then
            If objHeadingNode.Text = strHeading Then
                Exit Do
            End If
        End If
        Set objNode = colColumnNodes.NextNode
    Loop While Not objNode Is Nothing

getcolumn_exit:
    Set GetColumn = objNode
    Set objNode = Nothing
    Exit Function

getcolumn_err:
    Debug.Print Err.Number, Err.Description
    GoTo getcolumn_exit
End Function
--
Sue Mosher, Outlook MVP
   Outlook and Exchange Solutions
   at http://www.slipstick.com

Quote:

> hi,

> It's still me :)
> Pardon.
> How can you find a particular node and remove it?
> I want to erase all node "orderby" and his child in a view
> xml but it's possible?

> Why? because i want to change the previous sort and the
> previus order must be erase to success.

> Thanks



Tue, 12 Oct 2004 23:35:58 GMT  
 Remove node in a view xml
Thank you very much !!!


Fri, 15 Oct 2004 14:54:16 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Remove All Nodes from a Tree View

2. XML copy subnodes from one node to another node in another doc

3. XML copy subnodes from one node to another node in another doc

4. Trying to append a simple XML document as a node in an XML document

5. XML: Using XPath navigation to enumerate certain xml nodes

6. hyperlinking a node in one xml file to a node in another xml file??? Best way??

7. XML root node not found in my document !!

8. Loading XML Nodes in a treeview control

9. Adding Nodes to TreeView and XML files

10. Q how would you go about renameing a node in a xml document

11. Selecting a node from an XML document

12. XML Node Lookup?

 

 
Powered by phpBB® Forum Software