{"title":"Query.SaveAsXml(Text) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/query/queryinstance-saveasxml-string-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-string-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-string-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":1,"title":"Query.SaveAsXml(Text) Method","slug":"querysaveasxmltext-method","at":0,"chars":1544},{"level":2,"title":"Syntax","slug":"syntax","at":210,"chars":62},{"level":2,"title":"Parameters","slug":"parameters","at":272,"chars":192},{"level":2,"title":"Return Value","slug":"return-value","at":464,"chars":233},{"level":2,"title":"Remarks","slug":"remarks","at":697,"chars":173},{"level":2,"title":"Open, Read, or Close semantics","slug":"open-read-or-close-semantics","at":870,"chars":276},{"level":2,"title":"Example","slug":"example","at":1146,"chars":180},{"level":2,"title":"Related information","slug":"related-information","at":1326,"chars":218}],"text":"# Query.SaveAsXml(Text) Method\n> Version: _Available or changed with runtime version 1.0._\nSaves the resulting data set of a query as XML\n> NOTE\n> This method is supported only in Business Central on-premises.\n## Syntax\n```al\n[Ok := ]  Query.SaveAsXml(FileName: Text)\n```\n## Parameters\nQuery\nType: query-data-type\nAn instance of the query-data-type data type.\nFileName\nType: ../text/text-data-type\nThe path and name of the file that you want to save the query 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 then saved in XML format in the file and location that is designated by the FileName 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 to save XML directly to a file, see Query.SaveAsXml(Integer, Text) Method) Method<query-saveasxml-integer-string-method>.\n## Related information\nQuery.SaveAsXml(Integer, Text) Method) Method<query-saveasxml-integer-string-method>\nquery-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}