Results 1 to 2 of 2

Thread: Problem with XML export

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2010
    Posts
    63

    Problem with XML export

    Hi to all.
    I need your help for 2 problems.

    Using this code
    Code:
            Dim xmlDecl As New XDeclaration("1.0", "UTF-8", "yes")
            Dim path As String = "G:\XML\VB\LoadExcelAndSaveXML2\Test41.xml"
            Dim header As XElement
            Dim detail As XElement
            Dim doc As XDocument
            header = <Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">
                         <CstmrCdtTrfInitn>
                             <GrpHdr>
                                 <MsgId><%= DataGridView1(0, 0).Value() %></MsgId>
                                 <CreDtTm><%= DataGridView1(1, 0).Value() %></CreDtTm>
                                 <NbOfTxs><%= DataGridView1(2, 0).Value() %></NbOfTxs>
                                 <CtrlSum><%= DataGridView1(3, 0).Value() %></CtrlSum>
                                 <InitgPty>
                                     <Id>
                                         <OrgId>
                                             <Othr>
                                                 <Id><%= DataGridView1(4, 0).Value() %></Id>
                                                 <Issr><%= DataGridView1(5, 0).Value() %></Issr>
                                             </Othr>
                                         </OrgId>
                                     </Id>
                                 </InitgPty>
                             </GrpHdr>
                         </CstmrCdtTrfInitn>
                     </Document>
            For Each row As DataGridViewRow In DataGridView1.Rows
                If row.IsNewRow Then Continue For
                detail = <PmtInf>
                             <PmtInfId><%= row.Cells(6).Value %></PmtInfId>
                             <PmtMtd><%= row.Cells(7).Value %></PmtMtd>
                             <BtchBookg><%= row.Cells(8).Value %></BtchBookg>
                             <PmtTpInf>
                                 <SvcLvl>
                                     <Cd><%= row.Cells(9).Value %></Cd>
                                 </SvcLvl>
                             </PmtTpInf>
                             <ReqdExctnDt><%= row.Cells(10).Value %></ReqdExctnDt>
                             <Dbtr>
                                 <Nm><%= row.Cells(11).Value %></Nm>
                                 <Id>
                                     <OrgId>
                                         <Othr>
                                             <Id><%= row.Cells(12).Value %></Id>
                                             <Issr><%= row.Cells(13).Value %></Issr>
                                         </Othr>
                                     </OrgId>
                                 </Id>
                             </Dbtr>
                             <DbtrAcct>
                                 <Id>
                                     <IBAN><%= row.Cells(14).Value %></IBAN>
                                 </Id>
                             </DbtrAcct>
                             <DbtrAgt>
                                 <FinInstnId>
                                     <BIC><%= row.Cells(15).Value %></BIC>
                                 </FinInstnId>
                             </DbtrAgt>
                             <CdtTrfTxInf>
                                 <PmtId>
                                     <EndToEndId><%= row.Cells(16).Value %></EndToEndId>
                                 </PmtId>
                                 <Amt>
                                     <InstdAmt Ccy=<%= row.Cells(18).Value %>><%= row.Cells(17).Value %></InstdAmt>
                                 </Amt>
                                 <CdtrAgt>
                                     <FinInstnId>
                                         <BIC><%= row.Cells(19).Value %></BIC>
                                     </FinInstnId>
                                 </CdtrAgt>
                                 <Cdtr>
                                     <Nm><%= row.Cells(20).Value %></Nm>
                                 </Cdtr>
                                 <CdtrAcct>
                                     <Id>
                                         <IBAN><%= row.Cells(21).Value %></IBAN>
                                     </Id>
                                 </CdtrAcct>
                                 <Purp>
                                     <Cd><%= row.Cells(21).Value %></Cd>
                                 </Purp>
                             </CdtTrfTxInf>
                         </PmtInf>
                header.Add(detail)
            Next
            doc = New XDocument(xmlDecl, header)
            doc.Save(path)
            MsgBox("Export Finished")
    I take this result
    Code:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">
      <CstmrCdtTrfInitn>
        <GrpHdr>
          <MsgId>HHHHHHHHHHHHHHHHHHHHHHHHHH</MsgId>
          <CreDtTm>HHHHHHHHHHHHHHHHHHHHHHH</CreDtTm>
          <NbOfTxs>HH</NbOfTxs>
          <CtrlSum>HHHHH.HH</CtrlSum>
          <InitgPty>
            <Id>
              <OrgId>
                <Othr>
                  <Id>HHH</Id>
                  <Issr>HHHHH</Issr>
                </Othr>
              </OrgId>
            </Id>
          </InitgPty>
        </GrpHdr>
      </CstmrCdtTrfInitn>
    
      <PmtInf xmlns="">
        <PmtInfId>DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD</PmtInfId>
        <PmtMtd>DDD</PmtMtd>
        <BtchBookg>DDDDD</BtchBookg>
        <PmtTpInf>
          <SvcLvl>
            <Cd>DDDD</Cd>
          </SvcLvl>
        </PmtTpInf>
        <ReqdExctnDt>DDDDDDDDDD</ReqdExctnDt>
        <Dbtr>
          <Nm>DDDDDDDDDDDD</Nm>
          <Id>
            <OrgId>
              <Othr>
                <Id>DDDDDDDDDDD</Id>
                <Issr>DDDDDDDDDDDDDDDDDDDD</Issr>
              </Othr>
            </OrgId>
          </Id>
        </Dbtr>
        <DbtrAcct>
          <Id>
            <IBAN>DDDDDDDDDDDDDDDDDDDDDDDDDDD</IBAN>
          </Id>
        </DbtrAcct>
        <DbtrAgt>
          <FinInstnId>
            <BIC>DDDDDDDDDDD</BIC>
          </FinInstnId>
        </DbtrAgt>
        <CdtTrfTxInf>
          <PmtId>
            <EndToEndId>DDDDDDDDDDD</EndToEndId>
          </PmtId>
          <Amt>
            <InstdAmt Ccy="EUR">DDD.DD</InstdAmt>
          </Amt>
          <CdtrAgt>
            <FinInstnId>
              <BIC>DDDDDDDDDDD</BIC>
            </FinInstnId>
          </CdtrAgt>
          <Cdtr>
            <Nm>DDDDDDDDDDD</Nm>
          </Cdtr>
          <CdtrAcct>
            <Id>
              <IBAN>DDDDDDDDDDDDDDDDDDDDDDDDDDD</IBAN>
            </Id>
          </CdtrAcct>
          <Purp>
            <Cd>DDDDDDDDDDDDDDDDDDDDDDDDDDD</Cd>
          </Purp>
        </CdtTrfTxInf>
      </PmtInf>
    </Document>
    I would like to know
    1) if it is possible all the details <PmtInf></PmtInf> get inserted before </CstmrCdtTrfInitn> and not after
    2) change the <PmtInf xmlns=""> to <PmtInf>

    Thanks and regards...

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,829

    Re: Problem with XML export

    1) I believe so... Look to see if there is an .InsertBefore method, use that instead if .Add ... I'm pretty sure there's a way to insert nodes at specific locations, I don't remember the specific name of the method though. --- AddFirst... that's the one you want... https://docs.microsoft.com/en-us/dot...System_Object_

    2) I'm not sure. I think it's adding it because there's one on the original root, and it's seeing this as a new standalone document... not sure though... NEver seen that happen before.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width