Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i have writen a write XML sub

 

   Private Sub WriteOpts_XML()
       Dim XMLobj As Xml.XmlTextWriter
       Dim ue As New System.[Text].UnicodeEncoding
       XMLobj = New Xml.XmlTextWriter("Opts.xml", ue)
       XMLobj.Formatting = Xml.Formatting.Indented
       XMLobj.Indentation = 3
       XMLobj.WriteStartDocument()
       XMLobj.WriteStartElement("EthylOpts")
       XMLobj.WriteAttributeString("PunishValue", cmbPun.SelectedIndex)
       XMLobj.WriteAttributeString("BanSetValue", cmbBan.SelectedIndex)
       XMLobj.WriteStartElement("Options")
       XMLobj.WriteAttributeString("Nickname", CFNick.Text)
       XMLobj.WriteAttributeString("PunishTime", txtpun.Text)
       XMLobj.WriteAttributeString("BanSettings", txtban.Text)
       XMLobj.WriteEndElement()
       XMLobj.Close()
   EndSub

 

it gives out this XML file

 

<?xml version="1.0" encoding="utf-16"?>
<EthylOpts PunishValue="6" BanSetValue="2">
  <Options Nickname="BlackCell" PunishTime="TextBox1" BanSettings="TextBox1" />
</EthylOpts>

 

now i cant get s read XML to read the XML file and put those values and text where they are supposed to be.

Posted

Something like the following should work for you, it is however by no means the only way of doing it. I'm a C# user myself, hopefully I translated it to vb correctly.

        Dim reader As New System.Xml.XmlTextReader("path")
       While reader.Read()
           If reader.NodeType = System.Xml.XmlNodeType.Element Then
               If reader.Name = "EthylOpts" Then
                   cmbPun.SelectedIndex = Single.Parse(reader.GetAttribute("PunishValue"))
                   cmbBan.SelectedIndex = Single.Parse(reader.GetAttribute("BanSetValue"))
               ElseIf reader.Name = "Options" Then
                   CFNick.Text = reader.GetAttribute("NickName")
                   txtpun.Text = reader.GetAttribute("PunishTime")
                   txtban.Text = reader.GetAttribute("BanSettings")
               End If
           End If
       End While

Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...