The project requires digitally signing the XML document before transmission. Using the example provided by Microsoft( link here), the following code forms part of the function called for digitally signing the XML:
XmlDsigExcC14NTransform canMethod = (XmlDsigExcC14NTransform)signedXml.SignedInfo.CanonicalizationMethodObject;
canMethod.InclusiveNamespacesPrefixList = "Sign";
This leads to addition of following tag in signed XML
<InclusiveNamespaces PrefixList="Sign" xmlns="http://www.w3.org/2001/10/xml-exc-c14n#" />
However, when this XML is being saved in the XML Datatype column in SQL Server 2014, the tag changes to following:
<InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="Sign" />
Please notice the order of attributes above (PrefixList has moved to the end)
I also tried making the column as nvarchar. But on fetching the XML file as string and converting it to XML type in stored procedure leads to same result. However, when I save it the XML containing PrefixList in the end, the order is maintained.
Although this does not affect the signature verification, but it is critical for the application to maintain the original order of attributes (changes the CRC32 code of the XML) . My question is how to prevent SQL Server from changing the order? Alternatively is to possible to somehow change the order of attributes generated from the code itself in the first place to match that in the SQL Server column? Please help.