XML Visual Basic Questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fremenusul

    XML Visual Basic Questions

    First let me say I am familar with programming, but not familiar with VB.net.

    I am loading an existing XML document with this procedure

    Dim xmlFile As String = "..\data\Produc ts.xml"
    Dim xmlDoc As XmlDocument

    Private Sub Zadig_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    Dim xmlTr As New XmlTextReader(x mlFile)

    While xmlTr.Read
    If xmlTr.Name = "id" AndAlso xmlTr.NodeType =
    XmlNodeType.Ele ment Then
    cmbProducts.Ite ms.Add(xmlTr.Re adString)
    End If
    End While
    xmlTr.Close()

    xmlDoc = New XmlDocument
    xmlDoc.Load(xml File)

    End Sub

    If I have a NEW form (IE-Products.vb), will I be able to reference the XML
    doc in Memory?

    Also, is there a good web reference that shows how to update
    XML data (In memory) and then write them back out to a file?

    Thanks,

    Michael

  • Cor Ligthert

    #2
    Re: XML Visual Basic Questions

    Fremenusul.

    When you start with VBNet or beter dotNet and will use XML, you have
    yourself first is this an data file or a document.

    When it is a data file you would first have a look at the dataset, because
    that has its own methods to handle elements, which are a lot easier than the
    loaddoc and the xmlreader.

    When you have more questions, please reply

    Cor


    Comment

    • Sean Hederman

      #3
      Re: XML Visual Basic Questions

      Each instance of form Zadig will have it's own copy of the xmlDoc variable,
      but other form types will not. To share the xmlDoc variable amoungst forms
      will require that you make it Public. A good way of exposing it would be the
      Singleton Pattern:

      Public Class Settings

      Private Shared xmlDoc As XmlDocument

      Public Shared Property Products As XmlDocument
      Get
      If xmlDoc Is Nothing Then
      ' Initialize & load xmlDoc here
      End If

      Return xmlDoc
      End Get
      End Property

      End Class

      Then to access the XmlDocument you'd just do:
      Settings.Produc ts

      Have a look at
      http://samples.gotdotnet.com/quickst...viewofxml.aspx for
      more information on using XML in an application.

      "fremenusul " <fremenusul@dis cussions.micros oft.com> wrote in message
      news:AB6FEA7E-05D6-402D-84A2-B55258B6D7D0@mi crosoft.com...[color=blue]
      > First let me say I am familar with programming, but not familiar with
      > VB.net.
      >
      > I am loading an existing XML document with this procedure
      >
      > Dim xmlFile As String = "..\data\Produc ts.xml"
      > Dim xmlDoc As XmlDocument
      >
      > Private Sub Zadig_Load(ByVa l sender As System.Object, ByVal e As
      > System.EventArg s) Handles MyBase.Load
      > Dim xmlTr As New XmlTextReader(x mlFile)
      >
      > While xmlTr.Read
      > If xmlTr.Name = "id" AndAlso xmlTr.NodeType =
      > XmlNodeType.Ele ment Then
      > cmbProducts.Ite ms.Add(xmlTr.Re adString)
      > End If
      > End While
      > xmlTr.Close()
      >
      > xmlDoc = New XmlDocument
      > xmlDoc.Load(xml File)
      >
      > End Sub
      >
      > If I have a NEW form (IE-Products.vb), will I be able to reference the XML
      > doc in Memory?
      >
      > Also, is there a good web reference that shows how to update
      > XML data (In memory) and then write them back out to a file?
      >
      > Thanks,
      >
      > Michael
      >[/color]


      Comment

      • fremenusul

        #4
        Re: XML Visual Basic Questions

        Why is datafile better? I am learning and want to understand the "why's" as
        much as the "how's".

        Thanks,

        Michael

        "Cor Ligthert" wrote:
        [color=blue]
        > Fremenusul.
        >
        > When you start with VBNet or beter dotNet and will use XML, you have
        > yourself first is this an data file or a document.
        >
        > When it is a data file you would first have a look at the dataset, because
        > that has its own methods to handle elements, which are a lot easier than the
        > loaddoc and the xmlreader.
        >
        > When you have more questions, please reply
        >
        > Cor
        >
        >
        >[/color]

        Comment

        • Patrice

          #5
          Re: XML Visual Basic Questions

          It's just about the programming model. Instead of seing your document as an
          XML file you'll see it at a collection of rows with columns as if it were
          coming from a DB...

          Patrice

          --

          "fremenusul " <fremenusul@dis cussions.micros oft.com> a écrit dans le message
          de news:7004A1AA-CF5F-47B6-8A79-6D53EBD858E5@mi crosoft.com...[color=blue]
          > Why is datafile better? I am learning and want to understand the "why's"[/color]
          as[color=blue]
          > much as the "how's".
          >
          > Thanks,
          >
          > Michael
          >
          > "Cor Ligthert" wrote:
          >[color=green]
          > > Fremenusul.
          > >
          > > When you start with VBNet or beter dotNet and will use XML, you have
          > > yourself first is this an data file or a document.
          > >
          > > When it is a data file you would first have a look at the dataset,[/color][/color]
          because[color=blue][color=green]
          > > that has its own methods to handle elements, which are a lot easier than[/color][/color]
          the[color=blue][color=green]
          > > loaddoc and the xmlreader.
          > >
          > > When you have more questions, please reply
          > >
          > > Cor
          > >
          > >
          > >[/color][/color]


          Comment

          • Cor Ligthert

            #6
            Re: XML Visual Basic Questions

            Fremesul,

            I checked it because I was surprised that I wrote "better". There is in my
            opinion no "best" solution, every solution has a better alternative and I
            don't know if that is in this case. I wrote "easier".

            However, the dataset is made to cooperate with SQL based databaseservers and
            has therefore every functionality to handle it.

            Basically it exist from collections of datatables, which have collections
            of datarows, which have collections of dataitems. The dataitems are
            described in datacolumns. While as well it is possible to make relations in
            this for the tables.

            It has a lot of standard methods in dotnet to send and use in different
            ways.

            To give you four samples in VBNet format,

            reading of a dataset from a disk is.
            mydataset.readX ML("path").
            writing
            mydataset.write XML("path")
            showing the complete dataset in a datagrid
            mydatagrid1.dat asource = mydataset
            getting the first item from the first row from the first table
            mydataset.table s(0).rows(0)(0)
            or when it would have had names
            mydataset.table s("myfirsttable ").rows(0).item s("MyFirstItem" )

            However, this is just the begin and all based on data.

            I hope this gives some ideas'

            Cor





            "fremenusul " <fremenusul@dis cussions.micros oft.com> schreef in bericht
            news:7004A1AA-CF5F-47B6-8A79-6D53EBD858E5@mi crosoft.com...[color=blue]
            > Why is datafile better? I am learning and want to understand the "why's"
            > as
            > much as the "how's".
            >
            > Thanks,
            >
            > Michael
            >
            > "Cor Ligthert" wrote:
            >[color=green]
            >> Fremenusul.
            >>
            >> When you start with VBNet or beter dotNet and will use XML, you have
            >> yourself first is this an data file or a document.
            >>
            >> When it is a data file you would first have a look at the dataset,
            >> because
            >> that has its own methods to handle elements, which are a lot easier than
            >> the
            >> loaddoc and the xmlreader.
            >>
            >> When you have more questions, please reply
            >>
            >> Cor
            >>
            >>
            >>[/color][/color]


            Comment

            • Cor Ligthert

              #7
              Re: XML Visual Basic Questions

              Patrice,
              [color=blue]
              > It's just about the programming model. Instead of seing your document as
              > an
              > XML file you'll see it at a collection of rows with columns as if it were
              > coming from a DB...[/color]

              In my opinion wrong; every dataset can be a XML file, not every XML file is
              a dataset.

              Cor


              Comment

              • Patrice

                #8
                Re: XML Visual Basic Questions

                Is this what I said ?

                Was just trying to respond to fremensul that wanted to know why you
                suggested to use a DataSet for XML data files. My remakrs about the
                programming model is to be taken in this context, not that you should always
                handle all XML files on earth using this programming model...

                Patrice
                --

                "Cor Ligthert" <notmyfirstname @planet.nl> a écrit dans le message de
                news:%23HLOjnMJ FHA.3484@TK2MSF TNGP12.phx.gbl. ..[color=blue]
                > Patrice,
                >[color=green]
                > > It's just about the programming model. Instead of seing your document as
                > > an
                > > XML file you'll see it at a collection of rows with columns as if it[/color][/color]
                were[color=blue][color=green]
                > > coming from a DB...[/color]
                >
                > In my opinion wrong; every dataset can be a XML file, not every XML file[/color]
                is[color=blue]
                > a dataset.
                >
                > Cor
                >
                >[/color]


                Comment

                • Cor Ligthert

                  #9
                  Re: XML Visual Basic Questions

                  Patrice,

                  Je pense que c'était mon mauvaise idée au sujet de votre texte.
                  I think that it was my wrong idea about your text.

                  Excusez-moi.
                  Sorry

                  :-)

                  Cor


                  Comment

                  • Patrice

                    #10
                    Re: XML Visual Basic Questions

                    Sorry, it sometimes a bit hard to express yourself or to understand what
                    others are saying. I even wondered before answering as this is not so
                    important fbut found a bit strange your response in this context.

                    Later in this group - you saw English is not my native language ;-)

                    Patrice

                    --

                    "Cor Ligthert" <notmyfirstname @planet.nl> a écrit dans le message de
                    news:%23BPr2FNJ FHA.1304@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                    > Patrice,
                    >
                    > Je pense que c'était mon mauvaise idée au sujet de votre texte.
                    > I think that it was my wrong idea about your text.
                    >
                    > Excusez-moi.
                    > Sorry
                    >
                    > :-)
                    >
                    > Cor
                    >
                    >[/color]


                    Comment

                    • fremenusul

                      #11
                      Re: XML Visual Basic Questions

                      Thanks to everyone that replied. I will be reading over all the answers and
                      most likley, asking lots more questions.

                      Thanks again.

                      "Cor Ligthert" wrote:
                      [color=blue]
                      > Fremesul,
                      >
                      > I checked it because I was surprised that I wrote "better". There is in my
                      > opinion no "best" solution, every solution has a better alternative and I
                      > don't know if that is in this case. I wrote "easier".
                      >
                      > However, the dataset is made to cooperate with SQL based databaseservers and
                      > has therefore every functionality to handle it.
                      >
                      > Basically it exist from collections of datatables, which have collections
                      > of datarows, which have collections of dataitems. The dataitems are
                      > described in datacolumns. While as well it is possible to make relations in
                      > this for the tables.
                      >
                      > It has a lot of standard methods in dotnet to send and use in different
                      > ways.
                      >
                      > To give you four samples in VBNet format,
                      >
                      > reading of a dataset from a disk is.
                      > mydataset.readX ML("path").
                      > writing
                      > mydataset.write XML("path")
                      > showing the complete dataset in a datagrid
                      > mydatagrid1.dat asource = mydataset
                      > getting the first item from the first row from the first table
                      > mydataset.table s(0).rows(0)(0)
                      > or when it would have had names
                      > mydataset.table s("myfirsttable ").rows(0).item s("MyFirstItem" )
                      >
                      > However, this is just the begin and all based on data.
                      >
                      > I hope this gives some ideas'
                      >
                      > Cor
                      >
                      >
                      >
                      >
                      >
                      > "fremenusul " <fremenusul@dis cussions.micros oft.com> schreef in bericht
                      > news:7004A1AA-CF5F-47B6-8A79-6D53EBD858E5@mi crosoft.com...[color=green]
                      > > Why is datafile better? I am learning and want to understand the "why's"
                      > > as
                      > > much as the "how's".
                      > >
                      > > Thanks,
                      > >
                      > > Michael
                      > >
                      > > "Cor Ligthert" wrote:
                      > >[color=darkred]
                      > >> Fremenusul.
                      > >>
                      > >> When you start with VBNet or beter dotNet and will use XML, you have
                      > >> yourself first is this an data file or a document.
                      > >>
                      > >> When it is a data file you would first have a look at the dataset,
                      > >> because
                      > >> that has its own methods to handle elements, which are a lot easier than
                      > >> the
                      > >> loaddoc and the xmlreader.
                      > >>
                      > >> When you have more questions, please reply
                      > >>
                      > >> Cor
                      > >>
                      > >>
                      > >>[/color][/color]
                      >
                      >
                      >[/color]

                      Comment

                      • fremenusul

                        #12
                        Re: XML Visual Basic Questions

                        A followup question...

                        If I use XmlDocument (DOM implimentation I believe) I can "append" data to
                        my XML file right (In memory). Then when I am done, I can "output" a xml file.

                        Is there somewhere that can explain this process clearly? Read in XML file,
                        modify the xml (in memory) then output it back out???

                        Thanks for any help.

                        "Sean Hederman" wrote:
                        [color=blue]
                        > Each instance of form Zadig will have it's own copy of the xmlDoc variable,
                        > but other form types will not. To share the xmlDoc variable amoungst forms
                        > will require that you make it Public. A good way of exposing it would be the
                        > Singleton Pattern:
                        >
                        > Public Class Settings
                        >
                        > Private Shared xmlDoc As XmlDocument
                        >
                        > Public Shared Property Products As XmlDocument
                        > Get
                        > If xmlDoc Is Nothing Then
                        > ' Initialize & load xmlDoc here
                        > End If
                        >
                        > Return xmlDoc
                        > End Get
                        > End Property
                        >
                        > End Class
                        >
                        > Then to access the XmlDocument you'd just do:
                        > Settings.Produc ts
                        >
                        > Have a look at
                        > http://samples.gotdotnet.com/quickst...viewofxml.aspx for
                        > more information on using XML in an application.
                        >
                        > "fremenusul " <fremenusul@dis cussions.micros oft.com> wrote in message
                        > news:AB6FEA7E-05D6-402D-84A2-B55258B6D7D0@mi crosoft.com...[color=green]
                        > > First let me say I am familar with programming, but not familiar with
                        > > VB.net.
                        > >
                        > > I am loading an existing XML document with this procedure
                        > >
                        > > Dim xmlFile As String = "..\data\Produc ts.xml"
                        > > Dim xmlDoc As XmlDocument
                        > >
                        > > Private Sub Zadig_Load(ByVa l sender As System.Object, ByVal e As
                        > > System.EventArg s) Handles MyBase.Load
                        > > Dim xmlTr As New XmlTextReader(x mlFile)
                        > >
                        > > While xmlTr.Read
                        > > If xmlTr.Name = "id" AndAlso xmlTr.NodeType =
                        > > XmlNodeType.Ele ment Then
                        > > cmbProducts.Ite ms.Add(xmlTr.Re adString)
                        > > End If
                        > > End While
                        > > xmlTr.Close()
                        > >
                        > > xmlDoc = New XmlDocument
                        > > xmlDoc.Load(xml File)
                        > >
                        > > End Sub
                        > >
                        > > If I have a NEW form (IE-Products.vb), will I be able to reference the XML
                        > > doc in Memory?
                        > >
                        > > Also, is there a good web reference that shows how to update
                        > > XML data (In memory) and then write them back out to a file?
                        > >
                        > > Thanks,
                        > >
                        > > Michael
                        > >[/color]
                        >
                        >
                        >[/color]

                        Comment

                        Working...