In addition to these two columns, the WITH clause also includes a column named Overflow that uses the @mp:xmltext meta-property to store the open content in the Overflow column. Exactly what is stored in the Overflow column depends on the third OpenXML parametera bit flag to modify how OpenXML works. The fourth bit in the bit flag alters what data the @mp:xmltext parameter returns. When you set the flag to 0 or omit the parameter, OpenXML returns the element the row selector specified, including all its attributes and descendants. If the flag is set to 1, as in Listing 2, then OpenXML returns only the attributes and descendants from the element the row selector specifiedthe ones that weren't otherwise selected in the WITH clause (the unconsumed data).
Figure 1 shows a sample row from the Products table containing data that Listing 2's INSERT statement produced. Notice how OpenXML formats the open content in the Overflow column (obtained from the @mp:xmltext meta-property). The content consists of a Product element that ensures that the column content is well-formed XML. Well-formed XML documents obey a set of rules spelled out in the XML specification. You can think of them as documents in which all elements are closed and attribute names are unique. The name of this element isn't significant; SQL Server chose the name Product because that's the name of the element the row selector specified. The Product element contains any attributes or descendants that weren't referenced in the WITH clausehere, the weight attribute and the QuantityPerUnit child element. The formatting is straightforward, so you could generate similar data without OpenXML. But OpenXML provides a convenient and powerful way to process XML by using T-SQL code.
Open Content Other Ways
Updategrams and XML Bulk Load offer functionality similar to OpenXML's but use an XML View to define the mapping between the XML and database tables. XML Views define how the elements and attributes of an XML document correspond to the rows and columns in your database. To construct XML Views, you use XSD schemas to describe an XML document's structure and content, then add annotations to define the mapping to your database. An annotated XSD schema is called a mapping schema. One annotation, overflow-field, lets you specify the name of the column to store open content in. You include the overflow-field annotation on an element in the mapping schema to indicate that the element contains open content to be stored in your database. Using overflow-field is similar in functionality to specifying the row selector of OpenXML. Both Updategrams and XML Bulk Load store the open content in a format identical to that of OpenXML, but neither supports the option to store all the attributes and descendants. They can store only the unconsumed datathat is, data that's not specifically mapped to the database by other annotations in the mapping schema.
As you revise existing XML applications or develop new ones, build those applications with extensibility in mind. By accounting for open content, you can ensure that your application continues to work properly even when it receives unexpected data.