Results 1 to 5 of 5

Thread: [RESOLVED] Generate an XML document from an Array

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Resolved [RESOLVED] Generate an XML document from an Array

    Class Code:
    Code:
    Public Class Product
        Public Property ProductID() As String
        Public Property ProductName() As String
        Public Property ProductPrice() As Decimal
        Public Property ProductExpDate() As Date
    End Class
    Code:
    Private Sub arraytoxml_Click(sender As Object, e As EventArgs) Handles arraytoxml.Click
            Dim Products() As Product =
                    {New Product With
                    {.ProductID = 3, .ProductName = "Product A",
                    .ProductPrice = 8.75,
                    .ProductExpDate = #2/2/2009#},
                    New Product With
                    {.ProductID = 4, .ProductName = "Product B",
                    .ProductPrice = 19.5},
                    New Product With
                    {.ProductID = 5, .ProductName = "Product C",
                    .ProductPrice = 21.25,
                    .ProductExpDate = #12/31/2010#}}
        End Sub
    How can I Generate the corresponding XML ?. Thank you

    Solved It !!!!. It works like this :


    Code:
    Private Sub arraytoxml_Click(sender As Object, e As EventArgs) Handles arraytoxml.Click
            Dim Products() As Product =
                    {New Product With
                    {.ProductID = 3, .ProductName = "Product A",
                    .ProductPrice = 8.75,
                    .ProductExpDate = #2/2/2009#},
                    New Product With
                    {.ProductID = 4, .ProductName = "Product B",
                    .ProductPrice = 19.5},
                    New Product With
                    {.ProductID = 5, .ProductName = "Product C",
                    .ProductPrice = 21.25,
                    .ProductExpDate = #12/31/2010#}}
    
    
    Dim prods = <Products>
                            <%= From prod In Products
                                Select <Product>
                                           <ID><%= prod.ProductID %></ID>
                                           <Name><%= prod.ProductName %></Name>
                                           <Price><%= prod.ProductPrice %></Price>
                                           <ExpirationDate>
                                               <%= prod.ProductExpDate %></ExpirationDate>
                                       </Product> %>
                        </Products>
    
            MsgBox(prods.ToString)
    
        End Sub
    XML :

    Code:
    <Products>
      <Product>
        <ID>3</ID>
        <Name>Product A</Name>
        <Price>8.75</Price>
        <ExpirationDate>2009-02-02T00:00:00</ExpirationDate>
      </Product>
      <Product>
        <ID>4</ID>
        <Name>Product B</Name>
        <Price>19.5</Price>
        <ExpirationDate>0001-01-01T00:00:00</ExpirationDate>
      </Product>
      <Product>
        <ID>5</ID>
        <Name>Product C</Name>
        <Price>21.25</Price>
        <ExpirationDate>2010-12-31T00:00:00</ExpirationDate>
      </Product>
    </Products>
    Solved It !!!!.
    Last edited by ebellounisoft; Sep 3rd, 2017 at 07:17 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Generate an XML document from an Array

    For future reference, it's preferable that you add a new post with a solution rather than editing the existing post. Also, please use the Thread Tools menu to mark your thread Resolved.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Re: Generate an XML document from an Array

    At first instance I did not know how to solve it. I waited for a solution and continue working with the problem and finally I solved it. So next time If I find a solution by myself I do not post it ? .Thank you.
    Last edited by ebellounisoft; Sep 3rd, 2017 at 08:29 PM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: [RESOLVED] Generate an XML document from an Array

    If you solve your problem on your own then it is a very good idea to post that solution. What I'm saying is that you should add a new post containing your solution to your thread rather than editing the original post.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Re: [RESOLVED] Generate an XML document from an Array

    Ok . Got It . Thank you and good night

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