Reputation: 245
If I have xml which have following some empty node like following.
<TAG ID="abc"></TAG>
when I modify/select this xml it returns the empty tags like
<TAG ID="abc" />
I want empty tags closed with </TAG>
closing like
Can I achieve this ...?
Upvotes: 0
Views: 569
Reputation: 6684
Please note that the serialization of an XML result in SQL Server is not going to be determined by XQuery itself but by the conversion of the XML datatype to a string representation. In your example
DECLARE @X XML; SET @X = '<TAG ID="abc"></TAG>'; SELECT @X;
You are not using XQuery, you are just using the XML Parser and the XML serializer.
Thus, even if we added the serialization options of XQuery vNext, they would not be having an impact.
As Michael Kay mentions, there is no difference between the two serialization. Why do you want to differentiate between the two? If you have a tool that requires that differentiation, I recommend to ask them to change it to make their parser compliant to the standard. Alternatively, see if you can find an XML Parser/serializer on the client-side that gives you options on how to serialize an empty content element.
If you require full lexical fidelity instead of XML Infoset fidelity in the database, I would recommend to store your XML in a varbinary(max) since that will preserve your encoding and every code-point you enter, at the cost of having to do runtime casts to XML to do any query processing.
Best regards Michael
Upvotes: 2
Reputation: 163458
Any application that consumes XML should treat and as equivalent, therefore XQuery processors assume that they are equivalent and that there is no legitimate reason why users should prefer one form over the other. (Similarly, for example, they don't allow you to ask for attributes to be in single rather than double quotes, or for spaces to be added around the "=" sign.)
Upvotes: 1
Reputation: 6229
In many XQuery 3.0 processors (BaseX, Saxon, etc.), "html" can be specified as serialization option, which will output empty elements in the the expected way:
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "html";
<TAG ID="abc"></TAG>
I can’t tell, however, when/if XQuery 3.0 will be supported in SQL Server, or if it provides another way to change the serialization defaults.
Upvotes: 0