Change the order of an XML tag via T-SQL

0

Hello

I'm having a demand where for a certain reason, XML was generated with the order of the tags exchanged ...: (

Scenario: I have a column in the SQL Server database (from the 2008 release) that contains NF-e XML saved from a Windows application. These XML, as I said earlier, were inserted with the order of the incorrect tags. Due to the number of incorrect records already inserted into the database, I thought about creating a script that would change the order of the tags as follows:

<tag>
   <tag2> Y </tag2>
   <tag1> Z </tag1>
</tag>

where the correct one would be:

<tag>
   <tag1> Z </tag1>
   <tag2> Y </tag2>
</tag>

<[...]>
   <infNFeSupl> 
      <urlChave>https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx</urlChave> 
      <qrCode><![CDATA[https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx?chNFe=43180803167598000104650010000003051845389930&nVersao=100&tpAmb=1&dhEmi=323031382d30382d30335430393a32363a33372d30333a3030&vNF=55.00&vICMS=0.00&digVal=6a467a6a633157556578702f30517536627a2f732f7271306933773d&cIdToken=000001&cHashQRCode=afc69d3001a635df776512e797ea3054d00054cf]]></qrCode>
    </infNFeSupl>
</[...]>

Here's my question: How would I make this change?

I found some examples of how to modify XML attributes, but not the tags themselves. I accept suggestions.

Thank you in advance. :)

    
asked by anonymous 21.09.2018 / 16:47

0 answers