Home » Microsoft » MB6-886 » Which XML will be extracted?
You are a database developer on an instance of SQL Server 2008. You execute the Transact-SQL code shown in the exhibit. (Click the Exhibit(s) button.)
Which XML will be extracted?
Exhibit:
A. <OutData>
<Items> <ID>22</ID> <Name>Custom Fitting</Name> <Model>X720</Model> </Items>
</OutData>
B. <OutData>
<Model>410</Model><Model>X720</Model>
</OutData>
C. <OutData>
<Model>X720</Model>
</OutData>
D. <OutData>
<Location LocID="200"> <Items> <ID>22</ID><Name>Custom Fitting</Name><Model>X720</Model> </Items> </Location>
</OutData>
Correct Answer: C
Explanation/Reference:
The query() method is used to query and retrieve XML elements and attributes from an XML instance. The method accepts a string argument to specify the element or attribute that should be extracted. In this scenario, you specify a query string of {/Root/Warehouse/Location[@LocID=200]/Items/Model}.
This extracts the <Model> element, which is a child of the <Items> element, from within the <Location> element with a LocID value of 200.
The given code will not extract the XML that contains two <Model> elements within an <OutData> element. This result could be generated from @xmlDoc using the following SELECT statement:
SELECT @xmlDoc.query(‘<OutData> {/Root/Warehouse/Location/Items/Model}</OutData>’);
The given code will not extract the XML that contains an <Items> element including the <ID>, <Name>, and <Model> subelements. This result could be generated from @xmlDoc using the following SELECT statement:
SELECT @xmlDoc.query(‘<OutData> {/Root/Warehouse/Location[@LocID=200]/Items}</OutData>’);
The given code will not extract the XML that contains a <Location> element including subelements. This result could be generated from @xmlDocusing the following SELECT statement:
SELECT @xmlDoc.query(‘<OutData> {/Root/Warehouse/Location[@LocID=200]}</OutData>’);