FileQueryConnection.Execute 方法 (XPathNavigator)

覆盖默认 Execute 方法,以允许指定插入所返回数据的另一位置。

命名空间:  Microsoft.Office.InfoPath
程序集:  Microsoft.Office.InfoPath(位于 Microsoft.Office.InfoPath.dll 中)

语法

声明
Public MustOverride Sub Execute ( _
    output As XPathNavigator _
)
用法
Dim instance As FileQueryConnection
Dim output As XPathNavigator

instance.Execute(output)
public abstract void Execute(
    XPathNavigator output
)

参数

  • output
    类型:System.Xml.XPath.XPathNavigator

    一个 XPathNavigator,指定要在其中插入所返回数据的表单的主要或辅助数据源中的一个 XML 节点。以 output 参数形式传递的 XPathNavigator 也可以指定将数据插入本地计算机上的任何 XML 文件,或插入保留在内存中的 XmlDocument

异常

异常 条件
WebException

查询操作失败。

ArgumentNullException

传递给此方法的参数为 空引用(无 在 Visual Basic 中)。

ArgumentException

传递给此方法的参数无效。例如,它的类型或格式有误。

备注

将 output 参数设置为 空引用(无 在 Visual Basic 中) 与使用默认 Execute 方法(继承自 DataConnection 基类)通过表单模板中定义的声明性设置返回数据有着同样的效果。

此成员只能由与当前打开的表单在相同域中运行的表单访问,或者由已授予跨域权限的表单访问。

可以通过 Microsoft InfoPath Filler 或 Web 浏览器内打开的表单中运行的代码访问此类型或成员。

示例

在以下示例中,将使用 FileQueryConnection 类的 Execute(output) 方法依据"List.xml"文件执行查询,并将输出存储在内存中创建的 XmlDocument 中。然后,该方法将在表单的 QueryOutput 域中显示存储在 XmlDocument 中的输出。

public void ExecuteOutput_Clicked(object sender, ClickedEventArgs e)
{
   // Create the XmlDocument to accept the query results.
   XmlDocument outputFile = new XmlDocument();
   outputFile.LoadXml(
      "<?xml version=\"1.0\" encoding=\"utf-8\" ?><outputRoot></outputRoot>");

   // Create XmlNamespaceManager for XmlDocument object. When
   // creating a more complex document, use AddNamespace method
   // to add a mapping from namespace prefix to namespace URL for 
   // each namespace to this object.
   XmlNamespaceManager outputFileNamespaceManager = 
      new XmlNamespaceManager(outputFile.NameTable);

   // Create an XPathNavigator positioned at the root of the
   // XmlDocument output file created above.
   XPathNavigator outputFileNavigator = outputFile.CreateNavigator();
   XPathNavigator outputRootNavigator = 
      outputFileNavigator.SelectSingleNode("/outputRoot", 
      outputFileNamespaceManager);

   // Query the XML file defined for the FileQueryConnection
   // and log the results in the XmlDocument created above.
    FileQueryConnection queryConnection = 
      (FileQueryConnection)(DataConnections["List.xml"]);
    queryConnection.Execute(outputRootNavigator);

   // Insert the results of the query from the XmlDocument in the 
   // QueryOutput field of the main data source of the form.
   XPathNavigator mainNavigator = MainDataSource.CreateNavigator();
   XPathNavigator queryOutputNavigator = 
      mainNavigator.SelectSingleNode("/my:myFields/my:QueryOutput",
      NamespaceManager);
    queryOutputNavigator.SetValue(outputRootNavigator.InnerXml);
}
Public Sub ExecuteOutput_Clicked(ByVal sender As Object , _
   ByVal e As ClickedEventArgs)
{
   ' Create the XmlDocument to accept the query results.
   Dim outputFile As XmlDocument = new XmlDocument()
   outputFile.LoadXml(
      "<?xml version=\"1.0\" encoding=\"utf-8\" ?><outputRoot></outputRoot>")

   ' Create XmlNamespaceManager for XmlDocument object. When
   ' creating a more complex document, use AddNamespace method
   ' to add a mapping from namespace prefix to namespace URL for 
   ' each namespace to this object.
   Dim outputFileNamespaceManager As XmlNamespaceManager  = _
      new XmlNamespaceManager(outputFile.NameTable)

   ' Create an XPathNavigator positioned at the root of the
   ' XmlDocument output file created above.
   Dim outputFileNavigator As XPathNavigator = _
      outputFile.CreateNavigator()
   Dim outputRootNavigator As XPathNavigator = 
      outputFileNavigator.SelectSingleNode("/outputRoot", 
      outputFileNamespaceManager)

   ' Query the XML file defined for the FileQueryConnection
   ' and log the results in the XmlDocument created above.
    Dim myQueryConnection As FileQueryConnection  = _
      DirectCast(DataConnections["List.xml"], FileQueryConnection)
    myQueryConnection.Execute(outputRootNavigator);

   ' Insert the results of the query from the XmlDocument 
   ' in the QueryOutput field of the main data source of the form.
   Dim mainNavigator As XPathNavigator  = _
      MainDataSource.CreateNavigator()
   Dim queryOutputNavigator As XPathNavigator  = 
      mainNavigator.SelectSingleNode("/my:myFields/my:QueryOutput", _
      NamespaceManager)
    queryOutputNavigator.SetValue(outputRootNavigator.InnerXml)
End Sub

另请参阅

引用

FileQueryConnection 类

FileQueryConnection 成员

Execute 重载

Microsoft.Office.InfoPath 命名空间