Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server VB.NET
- <ROOT>
- <HEADER>
  <COMPANY_CODE>GULMOHAR</COMPANY_CODE>
  <BATCH_DATE>13/01/2011</BATCH_DATE>
  </HEADER>
- <KYCDATA>
  <APP_UPDTFLG>01</APP_UPDTFLG>
  <APP_POS_CODE>GULMOHAR</APP_POS_CODE>
  <APP_TYPE>I</APP_TYPE>
  <APP_NO>00001</APP_NO>
  <APP_DATE>02/01/2012</APP_DATE>
  <APP_PAN_NO>ABBDE1234J</APP_PAN_NO>
  <APP_PAN_COPY>Y</APP_PAN_COPY>
  <APP_EXMT>N</APP_EXMT>
  <APP_EXMT_CAT />
  <APP_EXMT_ID_PROOF>01</APP_EXMT_ID_PROOF>
  <APP_IPV_FLAG>Y</APP_IPV_FLAG>
  <APP_IPV_DATE>13/01/2012</APP_IPV_DATE>
  <APP_GEN>M</APP_GEN>
  <APP_NAME>SANDEEP CHAVAN</APP_NAME>
  <APP_F_NAME>HANMANT CHAVAN</APP_F_NAME>
  <APP_REGNO />
  <APP_DOB_INCORP>05/10/1980</APP_DOB_INCORP>
  <APP_COMMENCE_DT />
  <APP_NATIONALITY>01</APP_NATIONALITY>
  <APP_OTH_NATIONALITY />
  <APP_FILLER3 />
  </KYCDATA>
- <FOOTER>
  <NO_OF_KYC_RECORDS>1</NO_OF_KYC_RECORDS>
  <NO_OF_ADDLDATA_RECORDS>0</NO_OF_ADDLDATA_RECORDS>
  </FOOTER>
  </ROOT>
 

 

Hi all, i want to generate xml file in the format shown above..i tried it and got something like
this.
 

<?xml version="1.0" standalone="yes" ?>
- <DocumentElement>
- <My>
  <ParamCd>0</ParamCd>
  <ParamShortName>FPAYINOUTDT</ParamShortName>
  <ParamDesc>Ledger Posting Date</ParamDesc>
  <ParamVal>2</ParamVal>
  <SegmentID>0</SegmentID>
  </My>
- <My>
  <ParamCd>1</ParamCd>
  <ParamShortName>SPAYINOUTDT</ParamShortName>
  <ParamDesc>Demat Posting Date</ParamDesc>
  <ParamVal>2</ParamVal>
  <SegmentID>0</SegmentID>
  </My>
 
  </DocumentElement>
 

and i want to add Header and footer to the file instead of "My" and document element.How can i do this...help me out
Posted 11-Feb-13 3:19am
Comments
CHill60 at 11-Feb-13 9:43am
   
Post your code as well
DileepkumarReddy at 11-Feb-13 9:58am
   
i am just collecting data in datatable and then datatable.writetoxml method..

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

DataTable is not enough for you Wink | ;)
You need to use DataSet[^] object and 3 of DataTable[^] objects, because xml file is simple database, which can store more than one table. Each element: HEADER, KYCDATA and FOOTER is a container for data...
 
Try this:
Private Sub WriteMyXML()
    Dim ds As Data.DataSet = Nothing
    Dim dt1 As Data.DataTable = Nothing, dt2 As Data.DataTable = Nothing, dt3 As Data.DataTable = Nothing
    Dim dr As Data.DataRow = Nothing, dc As Data.DataColumn = Nothing
 
    Try
 
        '<ROOT>
        ds = New Data.DataSet("ROOT")
 
        '- <HEADER>
        '  <COMPANY_CODE>GULMOHAR</COMPANY_CODE>
        '  <BATCH_DATE>13/01/2011</BATCH_DATE>
        '</HEADER>

        dt1 = New Data.DataTable("HEADER")
        dc = New Data.DataColumn("COMPANY_CODE", GetType(String))
        dt1.Columns.Add(dc)
        dc = New Data.DataColumn("BATCH_DATE", GetType(Date))
        dt1.Columns.Add(dc)
        dr = dt1.NewRow
        dr.Item("COMPANY_CODE") = "GULMOHAR"
        dr.Item("BATCH_DATE") = DateTime.Parse("02/01/2012")
        dt1.Rows.Add(dr)
 

        '- <KYCDATA>
        '  <APP_UPDTFLG>01</APP_UPDTFLG>
        '  <APP_POS_CODE>GULMOHAR</APP_POS_CODE>
        '  <APP_TYPE>I</APP_TYPE>
        '  <APP_NO>00001</APP_NO>
        '  <APP_DATE>02/01/2012</APP_DATE>
        '  <APP_PAN_NO>ABBDE1234J</APP_PAN_NO>
        '  <APP_PAN_COPY>Y</APP_PAN_COPY>
        '  <APP_EXMT>N</APP_EXMT>
        '  <APP_EXMT_CAT />
        '  <APP_EXMT_ID_PROOF>01</APP_EXMT_ID_PROOF>
        '  <APP_IPV_FLAG>Y</APP_IPV_FLAG>
        '  <APP_IPV_DATE>13/01/2012</APP_IPV_DATE>
        '  <APP_GEN>M</APP_GEN>
        '  <APP_NAME>SANDEEP CHAVAN</APP_NAME>
        '  <APP_F_NAME>HANMANT CHAVAN</APP_F_NAME>
        '  <APP_REGNO />
        '  <APP_DOB_INCORP>05/10/1980</APP_DOB_INCORP>
        '  <APP_COMMENCE_DT />
        '  <APP_NATIONALITY>01</APP_NATIONALITY>
        '  <APP_OTH_NATIONALITY />
        '  <APP_FILLER3 />
        '</KYCDATA>

        dt2 = New Data.DataTable("KYCDATA")
        dc = New Data.DataColumn("APP_UPDTFLG", GetType(String))
        dt2.Columns.Add(dc)
        dc = New Data.DataColumn("APP_POS_CODE", GetType(String))
        dt2.Columns.Add(dc)
        dc = New Data.DataColumn("APP_NO", GetType(Integer))
        dt2.Columns.Add(dc)
        dc = New Data.DataColumn("APP_DATE", GetType(Date))
        dt2.Columns.Add(dc)
        'and so on...
        dr = dt2.NewRow
        dr.Item("APP_UPDTFLG") = "01"
        dr.Item("APP_POS_CODE") = "GULMOHAR"
        dr.Item("APP_NO") = 1
        dr.Item("APP_POS_CODE") = DateTime.Parse("02/01/2012")
        dt2.Rows.Add(dr)
 
        '- <FOOTER>
        '  <NO_OF_KYC_RECORDS>1</NO_OF_KYC_RECORDS>
        '  <NO_OF_ADDLDATA_RECORDS>0</NO_OF_ADDLDATA_RECORDS>
        '</FOOTER>

        dt3 = New Data.DataTable("FOOTER")
        dc = New Data.DataColumn("NO_OF_KYC_RECORDS", GetType(Integer))
        dt3.Columns.Add(dc)
        dc = New Data.DataColumn("NO_OF_ADDLDATA_RECORDS", GetType(Integer))
        dt3.Columns.Add(dc)
        dr = dt3.NewRow
        dr.Item("NO_OF_KYC_RECORDS") = 1
        dr.Item("NO_OF_ADDLDATA_RECORDS") = 0
        dt3.Rows.Add(dr)
 

        ds.Tables.Add(dt1)
        ds.Tables.Add(dt2)
        ds.Tables.Add(dt3)
        '</ROOT>

        ds.WriteXml("E:\myXml.xml", XmlWriteMode.IgnoreSchema)
 
    Catch ex As Data.DataException
        Console.WriteLine(ex.Message)
 
    Catch ex As Exception
        Console.WriteLine(ex.Message)
 
    End Try
 

End Sub
 

Output:
<?xml version="1.0" standalone="yes" ?>
- <ROOT>
- <HEADER>
  <COMPANY_CODE>GULMOHAR</COMPANY_CODE>
  <BATCH_DATE>2012-02-01T00:00:00+01:00</BATCH_DATE>
  </HEADER>
- <KYCDATA>
  <APP_UPDTFLG>01</APP_UPDTFLG>
  <APP_POS_CODE>2012-02-01 00:00:00</APP_POS_CODE>
  <APP_NO>1</APP_NO>
  </KYCDATA>
- <FOOTER>
  <NO_OF_KYC_RECORDS>1</NO_OF_KYC_RECORDS>
  <NO_OF_ADDLDATA_RECORDS>0</NO_OF_ADDLDATA_RECORDS>
  </FOOTER>
  </ROOT>
  Permalink  
v2
Comments
CHill60 at 11-Feb-13 16:22pm
   
My +5 ... would get it twice over as the question was so vague!
Maciej Los at 11-Feb-13 16:25pm
   
Thank you, Caroline (am i right?) ;)
CHill60 at 11-Feb-13 16:31pm
   
Not in a space where I can test it right now but certainly looked ok to me with a "manual" walkthru. Hope you haven't made any typo's because there are guys in here that will flame you if you have ;-p Seriously it looks pretty d**n close to his expected results
Maciej Los at 11-Feb-13 16:43pm
   
I really don't want to help this way, but sometimes it's only one way out: "Coffe on the table" - as we said in Poland ;)
DileepkumarReddy at 12-Feb-13 3:13am
   
Thank you Los..
Maciej Los at 12-Feb-13 3:15am
   
You're welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 350
1 Sergey Alexandrovich Kryukov 320
2 BillWoodruff 309
3 George Jonsson 274
4 OriginalGriff 237
0 OriginalGriff 4,903
1 CPallini 3,960
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,786
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100