Worksheet.XmlDataQuery Method (2007 System)

Gets a Range object that represents the cells mapped to a particular XPath. Gets nulla null reference (Nothing in Visual Basic) if the specified XPath has not been mapped to the worksheet, or if the mapped range is empty.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
Public Function XmlDataQuery ( _
    XPath As String, _
    SelectionNamespaces As Object, _
    Map As Object _
) As Range
'Usage
Dim instance As Worksheet 
Dim XPath As String 
Dim SelectionNamespaces As Object 
Dim Map As Object 
Dim returnValue As Range 

returnValue = instance.XmlDataQuery(XPath, _
    SelectionNamespaces, Map)
public Range XmlDataQuery(
    string XPath,
    Object SelectionNamespaces,
    Object Map
)
public:
Range^ XmlDataQuery(
    String^ XPath, 
    Object^ SelectionNamespaces, 
    Object^ Map
)
public function XmlDataQuery(
    XPath : String, 
    SelectionNamespaces : Object, 
    Map : Object
) : Range

Parameters

  • SelectionNamespaces
    Type: System.Object

    A space-delimited string that contains the namespaces referenced in the XPath parameter. A run-time error is generated if one of the specified namespaces cannot be resolved.

  • Map
    Type: System.Object

    An XmlMap. Specify an XML map if you want to query for the XPath within a specific map.

Return Value

Type: Range
A Range object that represents the cells mapped to a particular XPath; nulla null reference (Nothing in Visual Basic) if the specified XPath has not been mapped to the worksheet, or if the mapped range is empty.

Remarks

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.

If the XPath exists within a column in an XML list, the Range object returned does not include the header row or the Insert row.

Optional Parameters

For information on optional parameters, see The Variable missing and Optional Parameters in Office Solutions.

Examples

The following code example uses the XmlDataQuery method to get the Range of cells mapped to a particular XPath.

This example is for a document-level customization.

Private Sub WorksheetQueryXmlData()
    Dim path As String = "/order/customer/address" 
    Dim namespaces As String = "xmlns=https://www.contoso.com/orders" 

    Dim range1 As Excel.Range = _
        Me.XmlDataQuery(path, namespaces)

    If range1 Is Nothing Then
        MsgBox("The specified XPath: '" & path & _
            "' has not been mapped to the worksheet, or the mapped " & _
                "range is empty.")
    End If 
End Sub
private void WorksheetQueryXmlData()
{
    string path = "/order/customer/address";
    string namespaces = "xmlns=https://www.contoso.com/orders";

    Excel.Range range1 = this.XmlDataQuery(path, namespaces, missing);

    if (range1 == null)
    {
        MessageBox.Show("The specified XPath: '" + path + 
            "' has not been mapped to the worksheet, or the mapped " +
            "range is empty.");
    }
}

.NET Framework Security

See Also

Reference

Worksheet Class

Worksheet Members

Microsoft.Office.Tools.Excel Namespace