Examines the image parameter, and returns an integer value indicating whether the parameter contains parsed XML data or other sorts of image data.
xmlrepresentation_call::= xmlrepresentation(image_expression)
An image_expression is an sql_query_expression whose datatype is image.
If the parameter of an xmlrepresentation call is null, the result of the call is null.
xmlrepresentation returns an integer 0 if the operand is parsed XML data, and a positive integer if the operand is either not parsed XML data or an all blank or empty string.
These examples use the sample_docs table described in Appendix B, “The sample_docs Example Table.”.
This example illustrates the basic xmlrepresentation function.
-- Return a non-zero value -- for a document that is not parsed XML select xmlrepresentation( xmlextract('/', '<a>A</a>' returns image) ----------- 1 -- Return a zero for a document that is parsed XML select xmlrepresentation( xmlparse( xmlextract('/', '<a>A</a>' returns image)) ----------- 0
Columns of datatype image can contain both parsed XML documents (generated by the xmlparse function) and unparsed XML documents. After the update commands in the following example, the image_doc column of the sample_docs table contains a parsed XML document for the titles document, an unparsed (character-string) XML document for the bookstore document, and a null for the publishers document (the original value).
update sample_docs set image_doc = xmlextract('/', text_doc returns image) where name_doc = 'bookstore' update sample_docs set image_doc = xmlparse(text_doc) where name_doc = 'titles'
You can use the xmlrepresentation function to determine whether the value of an image column is a parsed XML document:
select name_doc, xmlrepresentation(image_doc)from sample_docs name_doc --------- ----------- bookstore 1 publishers NULL titles 0 (3 rows affected)
You can update an image column and set all of its values to parsed XML documents. If the image column contains a mixture of parsed and unparsed XML documents, a simple update raises an exception.
update sample_docs set image_doc = xmlparse(image_doc) Msg 14904, Level 16, State 0: Line 1: XMLPARSE: Attempt to parse an already parsed XML document.
You can avoid such an exception by using the xmlrepresentation function:
update sample_docs set image_doc = xmlparse(image_doc) where xmlrepresentation(image_doc) != 0 (1 row affected)
The following command restores the sample_docs table to its original state.
update sample_docs set image_doc = null