Compartilhar via


FileQueryConnection.Execute(XPathNavigator) Método

Definição

Substitui o método padrão Execute() para permitir que a especificação de um local diferente insira os dados retornados.

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)

Parâmetros

output
XPathNavigator

Um XPathNavigator que especifica um nó XML na fonte de dados primária ou secundária do formulário no qual inserir os dados retornados. O XPathNavigator passou como o output parâmetro também pode especificar para inserir os dados em qualquer arquivo XML no computador local ou em um XmlDocument mantido na memória.

Exceções

A operação de consulta falhou.

O parâmetro passado para esse método é uma referência nula (Nada no Visual Basic).

O parâmetro passado para esse método não é válido. Por exemplo, ele é do tipo ou formato errado.

Exemplos

No exemplo a seguir, o método Execute(output) da FileQueryConnection classe é usado para executar uma consulta no arquivo "List.xml" e armazenar a saída em um XmlDocument criado na memória. Em seguida, ele exibe a saída armazenada no XmlDocument no campo QueryOutput do formulário.

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

Comentários

Definir o output parâmetro como uma referência nula (Nada no Visual Basic) tem o mesmo efeito que usar o método Execute padrão (herdado da DataConnection classe base) para retornar dados usando as configurações declarativas definidas no modelo de formulário.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed from code running in forms opened in Microsoft InfoPath Filler or in a Web browser.

Aplica-se a