Results 1 to 11 of 11

Thread: [RESOLVED] write an XML file - help?

  1. #1

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Resolved [RESOLVED] write an XML file - help?

    I am looking for an example of how to write an XML file using VB.NET? I tried searching the MSDN site for "How to" but nothing specific came up. I am new to VB.NET and would appreciate some pointers.
    He who never made a mistake never made a discovery?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: write an XML file - help?


  3. #3

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: write an XML file - help?

    I don't think thats what I am looking for, that example requires a server, what I am doing is a stand alone application. I have button on my form that launches a Openfiledialog and I need to take the file name I click on and write it to a xml file.
    He who never made a mistake never made a discovery?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: write an XML file - help?

    You can ignore the 'server' bit. It shows you how to use the XMLDocument object to create an XML file.

    Have a look here, for example:

    XMLDocument.Save()
    http://msdn.microsoft.com/library/de...sSaveTopic.asp

  5. #5

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: write an XML file - help?

    I think I bit off more then I can shew

    It doesn't say how to use the example. Do I need an XML Document Object on my form?
    He who never made a mistake never made a discovery?

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: write an XML file - help?

    There's a sample right there on the page,

    VB Code:
    1. Imports System
    2. Imports System.Xml
    3.  
    4. public class Sample
    5.  
    6.   public shared sub Main()
    7.  
    8.     ' Create the XmlDocument.
    9.     Dim doc as XmlDocument = new XmlDocument()
    10.     doc.LoadXml("<item><name>wrench</name></item>")
    11.  
    12.    ' Add a price element.
    13.    Dim newElem as XmlElement = doc.CreateElement("price")
    14.    newElem.InnerText = "10.95"
    15.    doc.DocumentElement.AppendChild(newElem)
    16.  
    17.     ' Save the document to a file and auto-indent the output.
    18.     Dim writer as XmlTextWriter = new XmlTextWriter("data.xml",nothing)
    19.     writer.Formatting = Formatting.Indented
    20.     doc.Save(writer)
    21.   end sub
    22. end class

    You need the System.Xml namespace imported at the top of your class.

  7. #7

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: write an XML file - help?

    Sorry, I saw it on that page, but I didn't/don't understand how to use it. Now in my project references I see System.XML, this is not what you are referring to is it?

    What I have on my form so far is a ShockwaveFlashObject and a button. All the button does right now is open a fileDialog box. What I want to do is find the flash flv file, write the file name to a xml file and have the flashobject play it.



    My code so far is this:
    VB Code:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.  
    4. #Region " Windows Form Designer generated code "
    5.  
    6.     Public Sub New()
    7.         MyBase.New()
    8.  
    9.         'This call is required by the Windows Form Designer.
    10.         InitializeComponent()
    11.  
    12.         'Add any initialization after the InitializeComponent() call
    13.  
    14.     End Sub
    15.  
    16.     'Form overrides dispose to clean up the component list.
    17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    18.         If disposing Then
    19.             If Not (components Is Nothing) Then
    20.                 components.Dispose()
    21.             End If
    22.         End If
    23.         MyBase.Dispose(disposing)
    24.     End Sub
    25.  
    26.     'Required by the Windows Form Designer
    27.     Private components As System.ComponentModel.IContainer
    28.  
    29.     'NOTE: The following procedure is required by the Windows Form Designer
    30.     'It can be modified using the Windows Form Designer.  
    31.     'Do not modify it using the code editor.
    32.     Friend WithEvents AxShockwaveFlash1 As AxShockwaveFlashObjects.AxShockwaveFlash
    33.     Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    34.     Friend WithEvents Button1 As System.Windows.Forms.Button
    35.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    36.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
    37.         Me.AxShockwaveFlash1 = New AxShockwaveFlashObjects.AxShockwaveFlash()
    38.         Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
    39.         Me.Button1 = New System.Windows.Forms.Button()
    40.         CType(Me.AxShockwaveFlash1, System.ComponentModel.ISupportInitialize).BeginInit()
    41.         Me.SuspendLayout()
    42.         '
    43.         'AxShockwaveFlash1
    44.         '
    45.         Me.AxShockwaveFlash1.Enabled = True
    46.         Me.AxShockwaveFlash1.Location = New System.Drawing.Point(16, 16)
    47.         Me.AxShockwaveFlash1.Name = "AxShockwaveFlash1"
    48.         Me.AxShockwaveFlash1.OcxState = CType(resources.GetObject("AxShockwaveFlash1.OcxState"), System.Windows.Forms.AxHost.State)
    49.         Me.AxShockwaveFlash1.Size = New System.Drawing.Size(536, 328)
    50.         Me.AxShockwaveFlash1.TabIndex = 0
    51.         '
    52.         'Button1
    53.         '
    54.         Me.Button1.Location = New System.Drawing.Point(384, 368)
    55.         Me.Button1.Name = "Button1"
    56.         Me.Button1.Size = New System.Drawing.Size(128, 40)
    57.         Me.Button1.TabIndex = 1
    58.         Me.Button1.Text = "Find FLV File"
    59.         '
    60.         'Form1
    61.         '
    62.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    63.         Me.ClientSize = New System.Drawing.Size(576, 518)
    64.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.AxShockwaveFlash1})
    65.         Me.Name = "Form1"
    66.         Me.Text = "FLV PLAYER"
    67.         CType(Me.AxShockwaveFlash1, System.ComponentModel.ISupportInitialize).EndInit()
    68.         Me.ResumeLayout(False)
    69.  
    70.     End Sub
    71.  
    72. #End Region
    73.  
    74.  
    75.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    76.         ' Displays an OpenFileDialog so the user can select a Cursor.
    77.         Dim openFileDialog1 As New OpenFileDialog()
    78.         openFileDialog1.Filter = "Flash Video Files|*.flv"
    79.         openFileDialog1.Title = "Select a FLV File"
    80.  
    81.         If openFileDialog1.ShowDialog() = DialogResult.OK Then
    82.             Dim sr As New System.IO.StreamReader(openFileDialog1.FileName)
    83.             MessageBox.Show(sr.ReadToEnd)
    84.             sr.Close()
    85.         End If
    86.  
    87.  
    88.     End Sub
    89.  
    90. End Class
    He who never made a mistake never made a discovery?

  8. #8

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: write an XML file - help?

    The example from the MSDN site presupposes that I have an existing xml document. Correct?
    He who never made a mistake never made a discovery?

  9. #9

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: write an XML file - help?

    ok, I added the XML namespace at the top of my class and put the code from MSDN in a button click event. When I click the button no XML file is written or written too. On the premise I need a data.xml file already existing I made one and saved it in the project folder.

    Either way nothing happens.

    What now?


    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         ' Create the XmlDocument.
    4.         Dim doc As XmlDocument = New XmlDocument
    5.         doc.LoadXml("<item><name>wrench</name></item>")
    6.  
    7.         ' Add a price element.
    8.         Dim newElem As XmlElement = doc.CreateElement("price")
    9.         newElem.InnerText = "10.95"
    10.         doc.DocumentElement.AppendChild(newElem)
    11.  
    12.         ' Save the document to a file and auto-indent the output.
    13.         Dim writer As XmlTextWriter = New XmlTextWriter("data.xml", Nothing)
    14.         writer.Formatting = Formatting.Indented
    15.         doc.Save(writer)
    16.  
    17.     End Sub
    He who never made a mistake never made a discovery?

  10. #10
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Re: write an XML file - help?

    The code above will create the 'data.xml' file in your project 'bin' directory, along with your .exe file.

    You could of course specify a directory other than that, eg "C:\Temp\data.xml"
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  11. #11

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: write an XML file - help?

    Hey thanks for replying. I found a good tutorial for writing XML file which has helped me out a great deal.

    http://www.vbdotnetheaven.com/Code/Apr2003/005.asp


    He who never made a mistake never made a discovery?

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