Modifier

Partager via


Query.SaveAsXml(Integer, OutStream) Method

Version: Available or changed with runtime version 1.0.

Saves the resulting data set of a query as an .xml file.

Syntax

[Ok := ]  Query.SaveAsXml(Number: Integer, OutStream: OutStream)

Parameters

Number
 Type: Integer
The ID of the query object that you want to save as an .xml file. If the query that you specify does not exist, then a run-time error occurs.

OutStream
 Type: OutStream
The stream that you want to save the query as XML to.

Return Value

[Optional] Ok
 Type: Boolean
true if the SaveAsXml succeeded, otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.

Remarks

When the SaveAsXML method is called, the dataset is generated as XML and streamed to the OutStream object designated by the OutStream parameter.

Open, Read, or Close semantics with the SaveAsXML method

The SaveAsXML method can be called at any place in the code and does not require that the Open, Read, or Close methods are called before it. When the SaveAsXML method is called, a new instance of the query is created. The query is implicitly opened, read, and closed. If there is currently a dataset in the opened state when the SaveAsXML method is called, then that instance is closed. This means that the following code is in-correct because the query is not open on the second Read call.

// Not correct way to use Query.SaveAsXML
Query.Open;  
Query.Read;  
Query.SaveAsXML(myOutStream);  
// Query is now closed, so next read call will fail
Query.Read;   

The correct code for this example is as follows.

// Correct way to use Query.SaveAsXML
Query.SaveAsXML(myOutStream);  
Query.Open;  
Query.Read;   

Example

The following example shows how to get data from a query with the name My Customer Query into an outstream for further processing.

var
    MyCustomerQuery: Query "My Customer Query";
    myOutStream: OutStream;
    OK: Boolean;
    Text000: Label 'Query was not saved.';
begin
    OK := MyCustomerQuery.SaveAsXML(Query::MyCustomerQuery, myOutStream);  
    if not OK then
          Error(Text000);  
end;

Query Data Type
Get Started with AL
Developing Extensions