--- title: "Use RAW Mode with FOR XML | Microsoft Docs" ms.custom: "" ms.date: "06/13/2017" ms.prod: "sql-server-2014" ms.reviewer: "" ms.technology: xml ms.topic: conceptual helpviewer_keywords: - "FOR XML RAW mode" - "XMLSCHEMA option" - "FOR XML clause, RAW mode" - "RAW FOR XML mode" - "ELEMENTS directive" - "RAW mode" - "XMLDATA option" ms.assetid: 02c1bc0b-760c-4589-9ab1-6927c6d9c734 author: MightyPen ms.author: genemi manager: craigg --- # Use RAW Mode with FOR XML RAW mode transforms each row in the query result set into an XML element that has the generic identifier \, or the optionally provided element name. By default, each column value in the rowset that is not NULL is mapped to an attribute of the \ element. If the ELEMENTS directive is added to the FOR XML clause, each column value is mapped to a subelement of the \ element. Together with the ELEMENTS directive, you can optionally specify the XSINIL option to map NULL column values in the result set to an element that has the attribute, xsi:nil=`"`true`"`. You can request a schema for the resulting XML. Specifying the XMLDATA option returns an in-line XDR schema. Specifying the XMLSCHEMA option returns an in-line XSD schema. The schema appears at the start of the data. In the result, the schema namespace reference is repeated for every top-level element. The BINARY BASE64 option must be specified in the FOR XML clause to return the binary data in base64-encoded format. In RAW mode, retrieving binary data without specifying the BINARY BASE64 option will result in an error. ## In This Section This section contains the following examples: - [Example: Retrieving Product Model Information as XML](example-retrieving-product-model-information-as-xml.md) - [Example: Specifying XSINIL with the ELEMENTS Directive](example-specifying-xsinil-with-the-elements-directive.md) - [Example: Requesting Schemas as Results with the XMLDATA and XMLSCHEMA Options](example-requesting-schemas-as-results-with-the-xmldata-and-xmlschema-options.md) - [Example: Retrieving Binary Data](example-retrieving-binary-data.md) - [Example: Renaming the <row> Element](example-renaming-the-row-element.md) - [Example: Specifying a Root Element for the XML Generated by FOR XML](example-specifying-a-root-element-for-the-xml-generated-by-for-xml.md) - [Example: Querying XMLType Columns](example-querying-xmltype-columns.md) ## See Also [Add Namespaces to Queries with WITH XMLNAMESPACES](add-namespaces-to-queries-with-with-xmlnamespaces.md) [Use AUTO Mode with FOR XML](use-auto-mode-with-for-xml.md) [Use EXPLICIT Mode with FOR XML](use-explicit-mode-with-for-xml.md) [Use PATH Mode with FOR XML](use-path-mode-with-for-xml.md) [SELECT (Transact-SQL)](/sql/t-sql/queries/select-transact-sql) [FOR XML (SQL Server)](../xml/for-xml-sql-server.md)