FileQueryConnection.Execute(XPathNavigator) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重写默认 Execute() 方法,以允许指定其他位置以插入返回的数据。
public:
abstract void Execute(System::Xml::XPath::XPathNavigator ^ output);
public abstract void Execute (System.Xml.XPath.XPathNavigator output);
override this.Execute : System.Xml.XPath.XPathNavigator -> unit
Public MustOverride Sub Execute (output As XPathNavigator)
参数
- output
- XPathNavigator
一个 , XPathNavigator 它指定主数据源或辅助数据源中的 XML 节点,该数据源的形式要插入返回的数据。 作为 output
参数传递的 XPathNavigator 还可以指定将数据插入本地计算机上的任何 XML 文件中,或将数据插入内存XmlDocument中。
例外
查询操作失败。
传递给此方法的参数是一个 null 引用, (Visual Basic) 中无任何内容。
传递给此方法的参数无效。 例如,它的类型或格式有误。
示例
在以下示例中,类的 FileQueryConnectionExecute (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
注解
将 output
参数设置为 null 引用 (Visual Basic) 中的 Nothing 与使用默认 Execute 方法的效果相同, (继承自 DataConnection 基类) 使用表单模板中定义的声明性设置返回数据。
此成员只能由与当前打开的表单在相同域中运行的表单访问,或者由已授予跨域权限的表单访问。
可以通过 Microsoft InfoPath Filler 或 Web 浏览器内打开的表单中运行的代码访问此类型或成员。