Compartir a través de


FileQueryConnection.Execute (Método) (XPathNavigator)

Anula el método Execute predeterminado para permitir que se especifique otra ubicación para insertar los datos devueltos.

Espacio de nombres: Microsoft.Office.InfoPath
Ensamblado: Microsoft.Office.InfoPath (en microsoft.office.infopath.dll)

Sintaxis

'Declaración
Public MustOverride Sub Execute ( _
    output As XPathNavigator _
)
'Uso
Dim instance As FileQueryConnection
Dim output As XPathNavigator

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

Parámetros

  • output
    Objeto XPathNavigator que especifica un nodo XML en el origen de datos principal o en uno secundario del formulario en que se van a insertar los datos devueltos. El objeto XPathNavigator que se pasa como parámetro output puede especificar también que los datos se inserten en cualquier archivo XML del equipo local, o en un XmlDocument guardado en la memoria.

Excepciones

Tipo de excepción Condición

WebException

Error de la operación de consulta.

ArgumentNullException

El parámetro que se ha pasado a este método es null.

ArgumentException

El parámetro que se ha pasado a este método no es válido. Por ejemplo, es de un tipo o formato no válido.

Comentarios

Si se establece el parámetro output en null, el resultado es el mismo que si se usa el método Execute predeterminado (heredado de la clase base DataConnection) para devolver datos utilizando las configuración declarativa definida en la plantilla de formulario.

Sólo pueden tener acceso a este miembro los formularios que se ejecuten en el mismo dominio que el formulario abierto actualmente o los formularios a los que se hayan concedido permisos entre dominios.

Se puede tener acceso a este tipo o miembro desde un código ejecutado en formularios abiertos en Microsoft Office InfoPath 2007 o en un explorador Web.

Ejemplo

En el ejemplo siguiente, se usa el método Execute(output) de la clase FileQueryConnection para ejecutar una consulta en el archivo "List.xml" y almacenar el resultado en un XmlDocument que se crea en la memoria. A continuación, se muestra el resultado guardado en XmlDocument en el campo QueryOutput del formulario.

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

Vea también

Referencia

FileQueryConnection (Clase)
FileQueryConnection (Miembros)
Microsoft.Office.InfoPath (Espacio de nombres)