本文介绍了使用VB.net和sql server生成Xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- <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>
大家好,我想以上面显示的格式生成xml文件..我试过并得到了类似
这个。
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
推荐答案
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>
这篇关于使用VB.net和sql server生成Xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!