{"title":"Query.SaveAsXml(OutStream) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/query/queryinstance-saveasxml-outstream-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/query/queryinstance-saveasxml-outstream-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/query/queryinstance-saveasxml-outstream-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Saves the resulting data set of a query as XML","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":107,"chars":68},{"level":2,"title":"Parameters","slug":"parameters","at":175,"chars":191},{"level":2,"title":"Return Value","slug":"return-value","at":366,"chars":233},{"level":2,"title":"Remarks","slug":"remarks","at":599,"chars":149},{"level":2,"title":"Open, Read, or Close semantics","slug":"open-read-or-close-semantics","at":748,"chars":276},{"level":2,"title":"Example","slug":"example","at":1024,"chars":130},{"level":2,"title":"Related information","slug":"related-information","at":1154,"chars":174}],"text":"> Version: _Available or changed with runtime version 1.0._\nSaves the resulting data set of a query as XML\n## Syntax\n```al\n[Ok := ]  Query.SaveAsXml(OutStream: OutStream)\n```\n## Parameters\nQuery\nType: query-data-type\nAn instance of the query-data-type data type.\nOutStream\nType: ../outstream/outstream-data-type\nThe stream that you want to save the query as XML to.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue 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.\n## Remarks\nWhen the SaveAsXML method is called, the dataset is generated and streamed to the OutStream object designated by the OutStream parameter.\n## Open, Read, or Close semantics\nThe 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. See query-saveasxml-integer-outstream-method#open-read-or-close-semantics-with-the-saveasxml-method.\n## Example\nFor example code on how to use Query.SaveAsXml with an OutStream object, see query-saveasxml-integer-outstream-method.\n## Related information\nquery-saveasxml-integer-outstream-method\nquery-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}