--- title: "Executing XPath Queries (SQLXML)" description: Learn how to execute an XPath query against a mapping schema using SQLXML Managed Classes. author: MikeRayMSFT ms.author: mikeray ms.date: "03/14/2017" ms.prod: sql ms.prod_service: "database-engine, sql-database" ms.technology: xml ms.topic: "reference" ms.custom: "seo-lt-2019" helpviewer_keywords: - "XPath queries [SQLXML], SQLXML Managed Classes" - "queries [SQLXML], SQLXML Managed Classes" - "Managed Classes [SQLXML], executing XPath queries" - "mapping schema [SQLXML], XPath queries" - "SQLXML Managed Classes, executing XPath queries" ms.assetid: 8bef4c4d-bf0e-4236-a875-fd7d3e058396 monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current" --- # Executing XPath Queries (SQLXML Managed Classes) [!INCLUDE [SQL Server Azure SQL Database](../../../includes/applies-to-version/sql-asdb.md)] This example illustrates how XPath queries are executed against a mapping schema. Consider this schema: ``` ``` This C# application executes an XPath query against this schema (MySchema.xml). > [!NOTE] > In the code, you must provide the name of the instance of Microsoft [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] in the connection string. ``` using System; using Microsoft.Data.SqlXml; using System.IO; class Test { static string ConnString = "Provider=SQLOLEDB;Server=(local);database=AdventureWorks;Integrated Security=SSPI"; public static int testXPath() { Stream strm; SqlXmlCommand cmd = new SqlXmlCommand(ConnString); cmd.CommandText = "Con"; cmd.CommandType = SqlXmlCommandType.XPath; cmd.RootTag = "ROOT"; cmd.SchemaPath = "MySchema.xml"; strm = cmd.ExecuteStream(); using (StreamReader sr = new StreamReader(strm)){ Console.WriteLine(sr.ReadToEnd()); } return 0; } public static int Main(String[] args) { testXPath(); return 0; } } ``` ### To test the application 1. Make sure that you have the [!INCLUDE[msCoName](../../../includes/msconame-md.md)] .NET Framework installed on your computer. 2. Save the XSD schema (MySchema.xml) that is provided in this example in a folder. 3. Save the C# code (DocSample.cs) that is provided in this example in the same folder in which the schema is stored. (If you store the files in a different folder, you will have to edit the code and specify the appropriate directory path for the mapping schema.) 4. Compile the code. To compile the code at the command prompt, use: ``` csc /reference:Microsoft.Data.SqlXML.dll DocSample.cs ``` This creates an executable (DocSample.exe). 5. At the command prompt, execute DocSample.exe.