Convert DataSet to XML …. with a twist

I ran into a situation where I had to have the output columns split up into two sections with my work at GE Healthcare. So DataSet.WriteXml wasnt going to work. So here is what I came up with…….Hope it helps someone…..

dsRW = RBDataManager.ExecuteSP_DS("usp_getRWData")
            Dim textWriter As XmlTextWriter = New XmlTextWriter("C:\\myXmFile.xml", Nothing)
            textWriter.Formatting = Formatting.Indented
            textWriter.WriteStartDocument()
            ‘textWriter.WriteStartElement("Bonddata">
            textWriter.WriteStartElement("Bonddata", "BranchCode=CAMRA NumberRows=" & dsRW.Tables(0).Rows.Count & " ExportDate=" & dFileDate.ToString("yyyy-MM-dd") & "")
            ‘textWriter.WriteElementString("Bonddata BranchCode=CAMRA NumberRows=" & dsRW.Tables(0).Rows.Count & " ExportDate=" & dFileDate.ToString("yyyy-MM-dd") & "", "")
            For Each drRW In dsRW.Tables(0).Rows
                textWriter.WriteStartElement("bond")
                textWriter.WriteStartElement("staticdata")
                textWriter.WriteElementString("portfolio", FixNull(drRW("portfolio")))
                textWriter.WriteElementString("symbol", FixNull(drRW("symb_pool")))
                textWriter.WriteElementString("cusip", FixNull(drRW("cusip")))
                textWriter.WriteElementString("isin", FixNull(drRW("isin")))
                textWriter.WriteElementString("descriptionone", FixNull(drRW("description1")))
                textWriter.WriteElementString("descriptiontwo", FixNull(drRW("description2")))
                textWriter.WriteElementString("issuer", FixNull(drRW("issuer")))
                textWriter.WriteElementString("intentcode", FixNull(drRW("intent_code")))
                textWriter.WriteElementString("internalrating", FixNull(drRW("int_rate")))
                textWriter.WriteElementString("moodycreditrating", FixNull(drRW("Moody_rate")))
                textWriter.WriteElementString("sandpcreditrating", FixNull(drRW("s_p_rate")))
                textWriter.WriteElementString("primarysic", FixNull(drRW("sic_prim")))
                textWriter.WriteElementString("secondarysic", FixNull(drRW("sic_secn")))
                textWriter.WriteEndElement()
                textWriter.WriteStartElement("economicdata")
                textWriter.WriteElementString("country", FixNull(drRW("country")))
                textWriter.WriteElementString("couponrate", FixNull(drRW("coupon_rate")))
                textWriter.WriteElementString("issuedate", FixNull(drRW("issue_date")))
                textWriter.WriteElementString("maturitydate", FixNull(drRW("maturity_date")))
                textWriter.WriteElementString("oddfirstpayment", FixNull(drRW("odd_first_pmt")))
                textWriter.WriteElementString("lastpaymentdate", FixNull(drRW("last_pmt_date")))
                textWriter.WriteElementString("nextpaymentdate", FixNull(drRW("next_pmt_date")))
                textWriter.WriteElementString("nextpaymentamount", FixNull(drRW("nextpaymentamount")))
                textWriter.WriteElementString("annuity", FixNull(drRW("perpetual")))
                textWriter.WriteElementString("convertible", FixNull(drRW("convertible")))
                textWriter.WriteElementString("interestfrequency", FixNull(drRW("int_freq_num")))
                textWriter.WriteElementString("interestcurrency", FixNull(drRW("inc_curr")))
                textWriter.WriteElementString("principalcurrency", drRW("prn_curr"))
                textWriter.WriteElementString("notional", FixNull(drRW("t_quantity_c")))
                textWriter.WriteElementString("paymentschedule", FixNull(drRW("pmt_schd")))
                textWriter.WriteElementString("callable", FixNull(drRW("calls")))
                textWriter.WriteElementString("puttable", FixNull(drRW("puts")))
                textWriter.WriteElementString("floating", FixNull(drRW("float_rate")))
                textWriter.WriteElementString("discountbond", FixNull(drRW("oid_price")))
                textWriter.WriteElementString("accrual", FixNull(drRW("accrual")))
                textWriter.WriteEndElement()
                textWriter.WriteEndElement()
            Next
            textWriter.WriteEndElement()

Consulting Requests

Feedback

Blog Front Page

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: