locked
trying to read xml file and write it to notepad like a batch file RRS feed

  • Question

  • User767034699 posted

    Im trying to read xml file having attributes like so

    <?xml version="1.0" ?>
    <ROOT>
    <BatchNumber ID="424325656" SourceName="koo" ItemType="1" SourceCode="UNI">        
      <Unique_number>000000225035729</Unique_number>
      <Destination>D</Destination>
      <Language>E</Language>
      <Postcode>7941</Postcode>
      <Addressee>D'Mitri Craig Matthews</Addressee>
      <Address_line_1>No. 13 Stevens Close</Address_line_1>
      <Address_line_3>Grassy Park</Address_line_3>
      <Address_line_4>Western Cape</Address_line_4>
      <E_mail_address>Dmitri.matthews@pgwc.gov.za</E_mail_address>
      <Cell_number>20727163125</Cell_number>
      <Date_of_Birth>8708165066087</Date_of_Birth>
      <Weight>56</Weight>
      <Shipping_Cost>45</Shipping_Cost>
    </BatchNumber>
    <BatchNumber ID="424326" SourceName="FLORIDA" ItemType="67" SourceCode="UNF">        
      <Unique_number>00000025535729</Unique_number>
      <Destination>D</Destination>
      <Language>E</Language>
      <Postcode>7941</Postcode>
      <Addressee>D'Mitri Craig Matthews</Addressee>
      <Address_line_1>No. 13 Stevens Close</Address_line_1>
      <Address_line_3>Grassy Park</Address_line_3>
      <Address_line_4>Western Cape</Address_line_4>
      <E_mail_address>Dmitri.matthews@pgwc.gov.za</E_mail_address>
      <Cell_number>29727163125</Cell_number>
      <Date_of_Birth>8708165066080</Date_of_Birth>
      <Weight>5</Weight>
      <Shipping_Cost>100</Shipping_Cost>
      </BatchNumber>
    </ROOT>
    

    Im using this code to read and write to notepad

     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
                  ''   Dim list As New List(Of Class1)()
            Dim ex As XElement = XElement.Load("C:Documents\lips\Batch123.xml")
            Dim node As IEnumerable(Of XNode) = From ele In ex.DescendantNodesAndSelf()
                                                      Select ele
            For Each xn As XNode In node
                If TypeOf xn Is XElement Then
                    Dim xa As XElement = TryCast(xn, XElement)
                    If xa.Name = "BatchNumber" Then
                        Dim value2 As String = xa.Value
                        For Each xatt As XAttribute In xa.Attributes()
                            If xatt.Name = "SourceCode" Then
                                Dim value As String = xatt.Value
                                objStreamWriter = New StreamWriter("C:\XML\batch.txt")
                                objStreamWriter.WriteLine("ClientID = " & xatt.Value)
                                objStreamWriter.WriteLine("CLIENTNAME = ")
                                objStreamWriter.WriteLine("BATCHNUMBER =")
                                objStreamWriter.WriteLine("ITEMTYPE = ")
                                objStreamWriter.WriteLine("@" & xa.Value)
                                objStreamWriter.Close()
                              
                            End If
                        Next
                    End If
                End If
            Next

    I want to write it like this format on the notepad

    CLIENTID ="UNI"
    CLIENTNAME = "koo"
    BATCHNUMBER = "10417"
    ITEMTYPE = "1"
    @RG607514616ZA,PRIMROSE HILL,N83/2014-326S,09/06/2014,FALSE,N,S FOURIE,,P PADAYACHEE,N,
    @RG607515015ZA,HOUGHTON,K10/2014-975S,09/06/2014,False,N,P BEUKES,P LESHABANA & LC.SEROPOLA,BB RAKOLA,N,
    @RG607515280ZA,HOUGHTON,K10/2014-976S,09/06/2014,False,N,P BEUKES,P LESHABANA & LC.SEROPOLA,BB RAKOLA,N,
    #

    please help

     

    Wednesday, August 13, 2014 2:35 AM

All replies

  • User-328728277 posted

    You can use Environment.NewLine, can you post the actual output you are receiving.

    Thursday, August 14, 2014 2:52 PM
  • User767034699 posted

    don't know how to use the environment.newline()

    and Im getting this output

    ClientID = UNI
    CLIENTNAME = koo
    BATCHNUMBER = 424325656
    ITEMTYPE = 1
    @000000225035729DE7941D'Mitri Craig MatthewsNo. 13 Stevens CloseGrassy ParkWestern CapeDmitri.matthews@pgwc.gov.za2072716312587081650660875645
    

    Friday, August 15, 2014 2:33 AM