none
Convert custom XML file to XML format using VB.net RRS feed

All replies

  • Below is the my input xml file data:

    <ICICPayments xmlns="http://elite.com/schemas/transaction/object/read/ACHPay">
      <PaymentRecord>    
        <PaymentDetails>      
          <PaymentAmount>148.39</PaymentAmount>
          <Date>2017-11-23</Date>      
        </PaymentDetails>    
      </PaymentRecord>
      <PaymentRecord>    
        <PaymentDetails>
          <PaymentAmount>990.44</PaymentAmount>
          <Date>2017-11-23</Date>      
        </PaymentDetails>    
      </PaymentRecord>  
    </ICICPayments>


    Excepted Out put: 

    <?xml version="1.0" encoding="utf-8"?>
    <Payments>
      <PaymentRecord>
        <PaymentDetails>
          <PaymentAmount>148.39</PaymentAmount>
          <Date>2017-11-23</Date>
        </PaymentDetails>
      </PaymentRecord>
      <PaymentRecord>
        <PaymentDetails>
          <PaymentAmount>990.44</PaymentAmount>
          <Date>2017-11-23</Date>
        </PaymentDetails>
      </PaymentRecord>
    </Payments>

    • Using VB.net Just we need to remove the 'ICICPayments' tag from xml file data.
    • Need to add new tag as 'Payments'

    Please let me know if you need any more details.

    Friday, May 25, 2018 12:59 PM
  • Can you get rid of the namespace?  Take a look at this(at the Stop) and you will see why I am asking.  Notice the namespaces in the output?

    Imports <xmlns="http://elite.com/schemas/transaction/object/read/superpayment">
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim xe As XElement
            xe = <SBIPayments xmlns="http://elite.com/schemas/transaction/object/read/superpayment">
                     <PaymentRecord>
                         <BeneficiaryDetails>
                             <ClientId>SBIPayments</ClientId>
                             <PaymentId>123</PaymentId>
                             <VCode>ABC-01</VCode>
                             <PayeeName>Big Bazar</PayeeName>
                         </BeneficiaryDetails>
                         <PaymentDetails>
                             <PaymentAmount>200.25</PaymentAmount>
                             <ValueDate>2018-05-26</ValueDate>
                         </PaymentDetails>
                         <RemittanceDetails>
                             <RemittanceRecord>
                                 <InvoiceNumberLabel>1234</InvoiceNumberLabel>
                                 <InvoiceDateLabel>2018-05-26</InvoiceDateLabel>
                                 <InvoiceAmountLabel>100.25</InvoiceAmountLabel>
                             </RemittanceRecord>
                             <RemittanceRecord>
                                 <InvoiceNumberLabel>456</InvoiceNumberLabel>
                                 <InvoiceDateLabel>2018-05-26</InvoiceDateLabel>
                                 <InvoiceAmountLabel>100.00</InvoiceAmountLabel>
                             </RemittanceRecord>
                         </RemittanceDetails>
                     </PaymentRecord>
                     <PaymentRecord>
                         <BeneficiaryDetails>
                             <ClientId>SBIPayments</ClientId>
                             <PaymentId>2345</PaymentId>
                             <VCode>XYZ-01</VCode>
                             <PayeeName>Big C</PayeeName>
                         </BeneficiaryDetails>
                         <PaymentDetails>
                             <PaymentAmount>500</PaymentAmount>
                             <ValueDate>2018-05-26</ValueDate>
                         </PaymentDetails>
                         <RemittanceDetails>
                             <RemittanceRecord>
                                 <InvoiceNumberLabel>5987</InvoiceNumberLabel>
                                 <InvoiceDateLabel>2018-05-26</InvoiceDateLabel>
                                 <InvoiceAmountLabel>250.00</InvoiceAmountLabel>
                             </RemittanceRecord>
                             <RemittanceRecord>
                                 <InvoiceNumberLabel>1234</InvoiceNumberLabel>
                                 <InvoiceDateLabel>2018-05-26</InvoiceDateLabel>
                                 <InvoiceAmountLabel>250.00</InvoiceAmountLabel>
                             </RemittanceRecord>
                         </RemittanceDetails>
                     </PaymentRecord>
                 </SBIPayments>
    
            Dim condensed As XElement = <SBIPayments></SBIPayments>
    
            Dim payProto As XElement = <Payment>
                                           <Remittance>
                                           </Remittance>
                                       </Payment>
    
            Dim pProto As XElement = <P ClientId="" PaymentId="" VCode="" PayeeName="" PaymentAmount="" ValueDate=""/>
    
            Dim rProto As XElement = <R InvoiceNumberLabel="" InvoiceDateLabel="" InvoiceAmountLabel=""/>
    
    
            For Each pel As XElement In xe...<PaymentRecord>
                Dim pay As New XElement(payProto)
                Dim p As XElement = New XElement(pProto)
                p.@ClientId = pel.<BeneficiaryDetails>.<ClientId>.Value
                '....
                pay.AddFirst(p)
                For Each rel As XElement In pel.<RemittanceDetails>
                    '...
                Next
                condensed.Add(pay)
            Next
            Stop 'LOOK at condensed.  
        End Sub
    End Class
    




    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."

    - from former MSDN User JohnWein

    SerialPort Info

    Multics - An OS ahead of its time.

    Friday, May 25, 2018 1:13 PM
  • Hi RamiReddy,

    As noted, please provide us with some insight as to what you have tried and what isn't working.

    If you just need a basic understanding of working with XML in VB.Net, please see the following article and related documentation.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/xml/

    Once you've given this a try, you are welcome to post back with any specific issues you may encounter.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Proposed as answer by Cor Ligthert Saturday, May 26, 2018 8:24 AM
    Friday, May 25, 2018 6:08 PM
    Moderator
  • This appears to be a duplicate request; I will merge it with your other thread to avoid duplicating answers.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, May 25, 2018 6:12 PM
    Moderator
  • Wow you provide an input with an expected output. But what is the expectation? You work at Appshark so show us what your app does to try to resolve the problem please.

    La vida loca

    Saturday, May 26, 2018 12:11 AM
  • In addition to Reed, 

    Read something about XML elements and XML attributes. 

    https://www.w3schools.com/xml/xml_dtd_el_vs_attr.asp


    Success
    Cor

    Saturday, May 26, 2018 8:28 AM