Chriz L

Chriz L

  • NA
  • 220
  • 50.9k

Export data in specific XML format

Aug 16 2017 4:07 AM
Hello,
 
I have this web application running and I need to export the data in specific XML format given.
I'm giving you an example of one table to be more specific. 
  1. CREATE TABLE [dbo].[TEST](  
  2.     [Id] [int] IDENTITY(1,1) NOT NULL,  
  3.     [Code] [intNULL,  
  4.     [A] [decimal](6, 2) NULL,  
  5.     [B] [decimal](6, 2) NULL,  
  6.     [C] [decimal](6, 2) NULL,  
  7.     [D] [decimal](6, 2) NULL,  
  8.     [E] [decimal](6, 2) NULL,  
  9.     [F] [decimal](6, 2) NULL,  
  10.     [G] [decimal](6, 2) NULL,  
  11.     [H] [decimal](6, 2) NULL,  
  12.  CONSTRAINT [PK_TEST] PRIMARY KEY CLUSTERED([Id] ASC))  
Each column belongs to a group. Group A (A,B,C,D), group B (E,F), group C(G,H).
 
The XML output must be like the following:
  1. <table t="TEST">  
  2.     <group g="A">  
  3.         <u val=**column code value**>  
  4.             <col c="A">  
  5.                 <value>**value of column A**</value>  
  6.             </col>  
  7.             <col c="B">  
  8.                 <value>**value of column B**</value>  
  9.             </col>  
  10.             <col c="C">  
  11.                 <value>**value of column C**</value>  
  12.             </col>  
  13.             <col c="D">  
  14.                 <value>**value of column D**</value>  
  15.             </col>  
  16.         </u>  
  17.     </group>  
  18.     <group g="B">  
  19.         <u val=**column code value**>  
  20.             <col c="E">  
  21.                 <value>**value of column E**</value>  
  22.             </col>  
  23.             <col c="F">  
  24.                 <value>**value of column F**</value>  
  25.             </col>                  
  26.         </u>  
  27.     </group>  
  28.     <group g="C">  
  29.         <u val=**column code value**>  
  30.             <col c="G">  
  31.                 <value>**value of column G**</value>  
  32.             </col>  
  33.             <col c="H">  
  34.                 <value>**value of column H**</value>  
  35.             </col>                  
  36.         </u>  
  37.     </group>  
  38. </table>  
Any ideas how to create the XML?
 
Thank you in advance. 
 
 

Answers (2)