An XML Example
Here is an XML example for ya:
[code:1]
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Xml;
using Server;
using Server.Network;
using Server.Guilds;
namespace Server.Web
{
public class PlayerList : Timer
{
public static void Initialize()
{
new PlayerList().Start();
}
public PlayerList() : base( TimeSpan.FromSeconds( 5.0 ), TimeSpan.FromSeconds( 60.0 ) )
{
Priority = TimerPriority.FiveSeconds;
}
protected override void OnTick()
{
if ( !Directory.Exists( "Saves/Web" ) )
Directory.CreateDirectory( "Saves/Web" );
using ( StreamWriter op = new StreamWriter( "Saves/Web/Players.xml" ) )
{
XmlTextWriter xml = new XmlTextWriter( op );
xml.Formatting = Formatting.Indented;
xml.IndentChar = '\t';
xml.Indentation = 1;
xml.WriteStartDocument( true );
xml.WriteStartElement( "WebData" );
xml.WriteAttributeString( "Created", DateTime.Now.ToString() );
xml.WriteAttributeString( "Updated", (DateTime.Now + this.Interval).ToString() );
foreach ( NetState state in NetState.Instances )
{
Mobile m = state.Mobile;
if ( m != null )
{
xml.WriteStartElement( "Mobile" );
xml.WriteAttributeString( "Name", m.Name );
xml.WriteAttributeString( "Access", m.AccessLevel.ToString());
xml.WriteAttributeString( "Kills", m.Kills.ToString());
xml.WriteAttributeString( "Karma", m.Karma.ToString());
xml.WriteAttributeString( "Fame", m.Fame.ToString());
Guild g = m.Guild;
if ( g != null )
{
xml.WriteStartElement( "Guild" );
xml.WriteAttributeString( "Key", g.Id.ToString() );
xml.WriteAttributeString( "GuildName", g.Name.Trim() );
xml.WriteAttributeString( "GuildTitle", m.GuildTitle );
xml.WriteAttributeString( "Abbreviation", g.Abbreviation );
xml.WriteEndElement();
}
xml.WriteStartElement( "Location" );
xml.WriteAttributeString( "Map", m.Map.ToString());
xml.WriteAttributeString( "X", m.X.ToString());
xml.WriteAttributeString( "Y", m.Y.ToString());
xml.WriteAttributeString( "Z", m.Z.ToString());
xml.WriteEndElement();
xml.WriteEndElement();
}
}
xml.Close();
}
}
}
}[/code:1]