A major contributor to the difference in storage between NVARCHAR(MAX) not discussed in the original answer is that NVARCHAR(MAX) does not use SCSU; using a NVARCHAR(N) + NVARCHAR(MAX) column pairs can reduce the storage requirements significantly, in addition to the Page Compression mentioned below. See Manual SCSU 'compression' in SQL Server 2017 for NVARCHAR(MAX)
—
One consideration that is not present in the other answers relates to Page Compression. With Page Compression, there are some very specific use cases, where storing XML as NVARCHAR(MAX) may be beneficial, depending on some specific factors.
This is a special scenario and should only be considered after data and usage analysis. In the scenario presented, this appears unlikely.
Considerations of when one might consider NVARCHAR(MAX) over XML:
- Page Compression is used. The third level is Dictionary Compression.
- The XML fragments are small (eg. < 1/4 page characters) and contain sufficient repetitive values and/or have common prefixes that page compression can eliminate.
- Disks costs $$$ and a primary business-driven goal is to reduce disk usage at the cost of other features. (Don't bother if disk space is ample!)
- The fields are saved in In-Row Data, as LOB data does not benefit from Page Compression.
- Page compression actually allows more rows to fit on a single page. (Don't bother if additional rows cannot be combined onto a single page!)
- XML queries against the fields are infrequent, as to avoid the cost of parsing. Such an approach is more effective for 'cold storage'.
Some drawbacks and counter-arguments:
- No native validation of XML in field, typed or otherwise.
- XML indices cannot be used.
- Pay CPU cost on every conversion of the text back to an XML type.
- Page Compression efficiency over XML encoding varies based on the amount of duplication in values (including text nodes) on records within a single page.
- Page Compression will not benefit large XML fragments moved to LOB. XML encoding is expected to result in smaller disk usage here. One might split fields and use COMPRESS for large XML data, although such is adding yet another level of complexity with additional concerns.
In a very specific scenario I've been working on, using NVARCHAR(MAX) results in 20%+ disk usage reduction when applied to many small fragments with high duplication. YMMV. Test with actual data and usages.
<foo></foo>
will become<foo />