Writer:
Code:
Private Sub _XMLWriter()
Try
Dim enc As New System.Text.UnicodeEncoding
Dim XMLobj As Xml.XmlTextWriter _
= New Xml.XmlTextWriter(Application.StartupPath & "\Data.xml", enc)
With XMLobj
.Formatting = Xml.Formatting.Indented
.Indentation = 4
.WriteStartDocument()
'general settings
.WriteStartElement("Data")
.WriteAttributeString("Servername", gen_name.Text)
.WriteAttributeString("ServerIP", gen_ip.Text)
.WriteAttributeString("RconPassword", gen_recon.Text)
.WriteAttributeString("ServerPort", gen_port.Text)
.WriteAttributeString("PlayerLimit", gen_player.Text)
.WriteAttributeString("Private Slots", gen_private.Text)
.WriteAttributeString("AdminName", gen_admin.Text)
.WriteAttributeString("Email", gen_email.Text)
.WriteAttributeString("WebsiteURL", gen_website.Text)
.WriteAttributeString("Location", gen_location.Text)
.WriteAttributeString("ModName", gen_modname.Text)
.WriteAttributeString("ModVersion", gen_modver.Text)
.WriteAttributeString("ModURL", gen_modurl.Text)
.WriteAttributeString("WebsiteURL", gen_mapurl.Text)
'gametype settings
.WriteAttributeString("TDMScore", tdm_score.Text)
.WriteAttributeString("TDMTime", tdm_time.Text)
.WriteAttributeString("TDMRound", tdm_round.Text)
.WriteAttributeString("TDMLives", tdm_lives.Text)
.WriteAttributeString("TDMRespawn", tdm_respawn.Text)
.WriteAttributeString("FFAScore", ffa_score.Text)
.WriteAttributeString("FFATime", ffa_time.Text)
.WriteAttributeString("FFARound", ffa_round.Text)
.WriteAttributeString("FFALives", ffa_lives.Text)
.WriteAttributeString("FFARespawn", ffa_respawn.Text)
.WriteAttributeString("DOMScore", dom_score.Text)
.WriteAttributeString("DOMTime", dom_time.Text)
.WriteAttributeString("DOMRound", dom_round.Text)
.WriteAttributeString("DOMLives", dom_lives.Text)
.WriteAttributeString("DOMRespawn", dom_respawn.Text)
.WriteAttributeString("KOTHScore", koth_score.Text)
.WriteAttributeString("KOTHTime", koth_time.Text)
.WriteAttributeString("KOTHRound", koth_round.Text)
.WriteAttributeString("KOTHLives", koth_lives.Text)
.WriteAttributeString("KOTHRespawn", koth_respawn.Text)
.WriteAttributeString("SABScore", sab_score.Text)
.WriteAttributeString("SABTime", sab_time.Text)
.WriteAttributeString("SABRound", sab_round.Text)
.WriteAttributeString("SABLives", sab_lives.Text)
.WriteAttributeString("SABRespawn", sab_respawn.Text)
.WriteAttributeString("SDBombtimer", sd_bomb.Text)
.WriteAttributeString("SDPlant", sd_plant.Text)
.WriteAttributeString("SDDefuse", sd_defuse.Text)
.WriteAttributeString("SDTime", sd_time.Text)
.WriteAttributeString("SDRound", sd_round.Text)
'map rotation
.WriteAttributeString("MapRotation", maprotate.Text)
'mod
.WriteAttributeString("NameofModFolder", modname.Text)
'other settings
.WriteAttributeString("ServerPassword", serverpw.Text)
.WriteAttributeString("PrivatePassword", privatepw.Text)
.WriteAttributeString("MaxRate", maxrate.Text)
.WriteAttributeString("FPS", fps.Text)
.WriteAttributeString("MaxPing", maxping.Text)
.WriteAttributeString("DropInactivePlayers", dropinactive.Text)
.WriteAttributeString("TimeoutForTeamkiller", teamkiller.Text)
.WriteAttributeString("DurationOfTempBan", tempbann.Text)
.WriteAttributeString("MaxHealth", maxhealth.Text)
.WriteAttributeString("HealthRegeneration", healthreg.Text)
.WriteAttributeString("Suiciderespawn", suiciderespawn.Text)
'start server
.WriteAttributeString("Multiplayer.ExeDirectory", mpexe.Text)
.WriteAttributeString("CommandLine", commandline.Text)
.WriteAttributeString("Nameofconfig", configname.Text)
.WriteAttributeString("Commands", rbcommands.Text)
.WriteEndElement()
.Close()
End With
Catch
End Try
End Sub
Reader:
Code:
Private Function XMLReader(ByVal Element As String, ByVal Feldname As String)
Dim value As String = 0
Dim _XMLReader As Xml.XmlReader _
= New Xml.XmlTextReader(Application.StartupPath & "\Data.xml")
With _XMLReader
Try
Do While .Read
Select Case .NodeType
Case Xml.XmlNodeType.Element
If .Name = Element Then
If .AttributeCount > 0 Then
While .MoveToNextAttribute
If .Name = Feldname Then
value = .Value
End If
End While
End If
End If
End Select
Loop
Catch
End Try
.Close()
End With
If value = String.Empty Then
Return ""
Else
Return value
End If
End Function
Reading the xml entries:
Code:
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
'general settings
gen_name.Text = XMLReader("Data", "Servername")
gen_ip.Text = XMLReader("Data", "ServerIP")
gen_recon.Text = XMLReader("Data", "RconPassword")
gen_port.Text = XMLReader("Data", "ServerPort")
gen_player.Text = XMLReader("Data", "PlayerLimit")
gen_private.Text = XMLReader("Data", "PrivateSlots")
gen_admin.Text = XMLReader("Data", "AdminName")
gen_email.Text = XMLReader("Data", "Email")
gen_website.Text = XMLReader("Data", "WebsiteURL")
gen_location.Text = XMLReader("Data", "Location")
gen_modname.Text = XMLReader("Data", "ModName")
gen_modver.Text = XMLReader("Data", "ModVersion")
gen_modurl.Text = XMLReader("Data", "ModURL")
gen_mapurl.Text = XMLReader("Data", "WebsiteURL")
'game types
'tdm
tdm_score.Text = XMLReader("Data", "TDMScore")
tdm_lives.Text = XMLReader("Data", "TDMLives")
tdm_round.Text = XMLReader("Data", "TDMRound")
tdm_time.Text = XMLReader("Data", "TDMTime")
tdm_respawn.Text = XMLReader("Data", "TDMRespawn")
'ffa
ffa_score.Text = XMLReader("Data", "FFAScore")
ffa_lives.Text = XMLReader("Data", "FFALives")
ffa_round.Text = XMLReader("Data", "FFARound")
ffa_time.Text = XMLReader("Data", "FFATime")
ffa_respawn.Text = XMLReader("Data", "FFARespawn")
'dom
dom_score.Text = XMLReader("Data", "DOMScore")
dom_lives.Text = XMLReader("Data", "DOMLives")
dom_round.Text = XMLReader("Data", "DOMRound")
dom_time.Text = XMLReader("Data", "DOMTime")
dom_respawn.Text = XMLReader("Data", "DOMRespawn")
'koth
koth_score.Text = XMLReader("Data", "KOTHScore")
koth_lives.Text = XMLReader("Data", "KOTHLives")
koth_round.Text = XMLReader("Data", "KOTHRound")
koth_time.Text = XMLReader("Data", "KOTHTime")
koth_respawn.Text = XMLReader("Data", "KOTHRespawn")
'sab
sab_score.Text = XMLReader("Data", "SABScore")
sab_lives.Text = XMLReader("Data", "SABLives")
sab_round.Text = XMLReader("Data", "SABRound")
sab_time.Text = XMLReader("Data", "SABTime")
sab_respawn.Text = XMLReader("Data", "SABRespawn")
'sd
sd_bomb.Text = XMLReader("Data", "SDBombtimer")
sd_plant.Text = XMLReader("Data", "SDPlant")
sd_defuse.Text = XMLReader("Data", "SDDefuse")
sd_round.Text = XMLReader("Data", "SDRound")
sd_time.Text = XMLReader("Data", "SDTime")
'map rotation
rb_maprotation.Text = XMLReader("Data", "MapRotation")
'mod name
modname.Text = XMLReader("Data", "NameofModFolder")
'other settings
serverpw.Text = XMLReader("Data", "ServerPassword")
privatepw.Text = XMLReader("Data", "Private Password")
maxrate.Text = XMLReader("Data", "MaxRate")
fps.Text = XMLReader("Data", "FPS")
maxping.Text = XMLReader("Data", "MaxPing")
dropinactive.Text = XMLReader("Data", "DropInactivePlayers")
teamkiller.Text = XMLReader("Data", "TimeoutForTeamkiller")
tempbann.Text = XMLReader("Data", "DurationOfTempBan")
maxhealth.Text = XMLReader("Data", "MaxHealth")
healthreg.Text = XMLReader("Data", "HealthRegeneration")
suiciderespawn.Text = XMLReader("Data", "SuicideRespawn")
'start server
mpexe.Text = XMLReader("Data", "Multiplayer.ExeDirectory")
commandline.Text = XMLReader("Data", "CommandLine")
configname.Text = XMLReader("Data", "Nameofconfig")
rbcommands.Text = XMLReader("Data", "Commands")
End Sub
HOWEVER, the textbox just shows a "0" as entry, even though there are other entries in the .xml...
I hope you can help me out
Thaaaaaaaankies