CustomXMLNode Methods

Name Returns Parameters Description

AppendChild Nodes

Name, Namespace URI, NodeType, NodeValue

AppendChild Subtree

XML

Delete

HasChild Nodes

Boolean

InsertNodes Before

Name, Namespace URI, NodeType, NodeValue, NextSibling

Insert

Subtree

NextSibling

RemoveChild

Child

Replace ChildNode

OldNode, Name, NamespaceURI, NodeType, NodeValue

Appends a single node as the last child under the context element node.

Inserts the specified subtree into the location just before the context node.

Removes the specified child node from the tree.

Removes the specified child node and replaces it with a different node in the same location.

Appends a single node as the last child under the context element node.

Adds a subtree as the last child under the context element node.

Deletes a specified node and all of its children.

Returns True if the specified node has child element nodes.

Inserts a new node just before the context node.

Inserts the specified subtree into the location just before the context node.

Removes the specified child node from the tree.

Removes the specified child node and replaces it with a different node in the same location.

Name

Returns

Parameters

Description

ReplaceChild Subtree

XML, OldNode

Removes the specified node and replaces it with a different subtree in the same location.

SelectNodes

Xpath

Selects a collection of nodes matching an XPath expression.

SelectSingle Node

Xpath

Selects a single node from a collection matching an XPath expression.

CustomXMLNode, CustomXMLNodes, and CustomXMLPart Example

The following routine adds a custom XML part to the active workbook and traverses the XML part using the new CustomXMLNodes collection:

Sub Add_Traverse_CustomXMLPart() Dim oCustomPart As CustomXMLPart Dim oCustomNode As CustomXMLNode Dim oCustomNodes As CustomXMLNodes

'Add a Custom XML Part from a file and then load

Set oCustomPart = ActiveWorkbook.CustomXMLParts.Add oCustomPart.Load "C:\EmployeeSales.xml"

'Return all nodes for the employee who has invoice amount over 3000

Set oCustomNodes = oCustomPart.SelectNodes("//Employee[InvoiceAmount>3000]") For Each oCustomNode In oCustomNodes

Debug.Print oCustomNode.Text Next

'Delete the Custom XML Part oCustomPart.Delete End Sub

To run this code, enter the following XML into Notepad and save as C:\ EmployeeSales.xml:

<EmployeeSales>

<Employee>

<Empid>2312</Empid>

<FirstName>Mike</FirstName>

<LastName>Alexander</LastName>

<InvoiceNumber>100</InvoiceNumber>

<InvoiceAmount>2300</InvoiceAmount>

</Employee>

<Employee>

<Empid>24601</Empid>

<FirstName>Stephen</FirstName>

<LastName>Bullen</LastName>

<InvoiceNumber>200</InvoiceNumber>

<InvoiceAmount>3211</InvoiceAmount>

</Employee>

</EmployeeSales>

Was this article helpful?

0 0

Post a comment