次の方法で共有


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
    フォームのプライマリ データ ソースまたはセカンダリ データ ソース内にある、返されたデータの挿入先とする XML ノードを指定する XPathNavigator。output パラメーターとして渡される XPathNavigator では、データの挿入先として、ローカル コンピューター上の任意の XML ファイルや、メモリに格納されている XmlDocument を指定することもできます。

例外

例外 条件
WebException

クエリ操作が失敗しました。

ArgumentNullException

このメソッドに渡されたパラメーターは null 参照 (Visual Basic ではNothing ) です。

ArgumentException

このメソッドに渡されたパラメーターは有効ではありません。たとえば、型または形式が正しくありません。

解説

output パラメーターを null 参照 (Visual Basic ではNothing ) に設定すると、既定の Execute メソッド (DataConnection 基本クラスから継承されたメソッド) を使用した場合と同じ結果が得られ、フォーム テンプレート内で定義されている宣言設定を使用したデータが返されます。

このメンバーには、現在開いているフォームと同じドメインで実行中のフォーム、またはクロスドメインのアクセス許可が与えられたフォームのみがアクセスできます。

この型またはメンバーには、Microsoft InfoPath Filler または Web ブラウザーで開かれたフォームを実行中のコードからアクセスできます。

次の例は、FileQueryConnection クラスの Execute(output) メソッドを使用して、"List.xml" ファイルに対してクエリを実行し、結果をメモリ内に作成された XmlDocument に保存します。次に、XmlDocument に保存されている出力をフォームの QueryOutput フィールドに表示します。

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 名前空間