I'm new to C#, frech from Learning C at Uni this year.
I'm writing a Chat Bot which will resond to commands, but I'm having some problems with one of the features.
Here's What's I've wrote so far:
public static void OnAlt2(Chat chat, CommandArgs e)
{
XmlTextReader altxml = new XmlTextReader("alts.xml");
altxml.Read();
while (altxml.Read())
{
if (altxml.NodeType == XmlNodeType.Element) // The node is an element.
{
altxml.MoveToNextAttribute(); // Read the attributes.
if(altxml.Value == e.Character)
{
altxml.MoveToNextAttribute();
string altlist = altxml.Value;
string[] arInfo = new string[7];
// define which character is seperating fields
char[] splitter = { ',' };
arInfo = altlist.Split(splitter);
for (int x = 0; x < arInfo.Length; x++)
{
if (arInfo[x] == e.Args[0])
{
e.Reply("True");
return;
}
}
e.Reply("Can't find that character from list: " + altlist);
e.Reply("Write to XML Attributes is incomplete");
}
}
}
}
Here is the XML:
I'm having trouble writing to the alts Attribute, everything I try either crashes or doesn't compile.
If Someone called Bareshaman types !alt Largoh, it will reply with "True", but if he types !alt Rago, it should add to the alt Attribute making the XML file read:
I'd also like it to add a new element when someone new types the command.
So if Bob comes along and types !alt Fred, the XML file should read:
I hope that's understandable.
Thanks very much
Mahesh ChandPosted Jul 17, 2008, 9:37 AM
Here is a good tutorial/ebook on XML programming in C#:
XML Programming in C# and .NET