XPath Object [Excel 2003 VBA Language Reference]

Multiple objects

Note  XML features, except for saving files in the XML Spreadsheet format, are available only in Microsoft Office Professional Edition 2003 and Microsoft Office Excel 2003.

Represents an XPath that has been mapped to a Range or ListColumn object.

Using the XPath Object

Use the SetValue method to map an XPath to a range or list column. The SetValue method is also used to change the properties of an existing XPath.

The following example creates an XML list based on the "Contacts" schema map that is attached to the workbook, then uses the SetValue method to bind each column to an XPath.

Sub CreateXMLList()
    Dim mapContact As XmlMap
    Dim strXPath As String
    Dim lstContacts As ListObject
    Dim lcNewCol As ListColumn

    ' Specify the schema map to use.
    Set mapContact = ActiveWorkbook.XmlMaps("Contacts")
    ' Create a new list.
    Set lstContacts = ActiveSheet.ListObjects.Add
    ' Specify the first element to map.
    strXPath = "/Root/Person/FirstName"
    ' Map the element.
    lstContacts.ListColumns(1).XPath.SetValue mapContact, strXPath

    ' Specify the element to map.
    strXPath = "/Root/Person/LastName"
    ' Add a column to the list.
    Set lcNewCol = lstContacts.ListColumns.Add
    ' Map the element.
    lcNewCol.XPath.SetValue mapContact, strXPath

    strXPath = "/Root/Person/Address/Zip"
    Set lcNewCol = lstContacts.ListColumns.Add
    lcNewCol.XPath.SetValue mapContact, strXPath
End Sub

Use the Clear method to remove an XPath that has been mapped to a range or list column.

Properties | Application Property | Creator Property | Map Property | Parent Property | Repeating Property | Value Property

Methods | Clear Method | SetValue Method

Parent Objects | ListColumn Object | Range Collection

Child Objects | XmlMap Object

See Also | XmlDataBinding Object | XmlMap Object | XmlMaps Collection | XmlNamespace Object | XmlNamespaces Collection | XmlSchema Object | XmlSchemas Collection