hi all
i am developing a small application that will allow the user to paste in admin logs which will then be converted into xml data.

The code works fine in VB.net but i am trying to convert it into C# as the application is written in c#

i am having issues with my writer.WriteElementString();

here is the clock of code of what i am trying to do.

StringBuilder sb = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.IndentChars = Convert.ToString((char) Keys.Tab); 
            settings.OmitXmlDeclaration = true;

            writer = XmlWriter.Create(sb, settings);
            writer.WriteStartElement("Players");

            Int16 countme;

            foreach (Match match in Regex.Matches(rawdata, pattern))
            {
                writer.WriteElementString("Admin", match.Groups.Item("Admin"));
                writer.WriteElementString("PlayerName", match.Groups.Item("PlayerName").Value);
                writer.WriteElementString("PlayerIP", match.Groups.Item("PlayerIP").Value);
                writer.WriteElementString("PlayerGuid", match.Groups.Item("PlayerGuid").Value);
                writer.WriteElementString("Action", match.Groups.Item("Action").Value);
                writer.WriteElementString("Server", match.Groups.Item("Server").Value);
                writer.WriteElementString("DateTime", match.Groups.Item("DateTime").Value);
            }

The error seems to ly with match.Groups.Item("{VALUE}");
"cannot resolve symbol ITEM"

any help would be gratefull
cheers

Edited 3 Years Ago by dualzNZ

to add on the whole methos looks like this

private void ConvertText(string dataIn)
        {

            string rawdata = dataIn;

            const string pattern = @"Admin:\s*(?<Admin>.*)\r\nPlayer\sName:\s*(?<PlayerName>.*)\r\nPlayer\sIp:\s*(?<PlayerIP>.*)\r\nPlayer\sGuid:\s*(?<PlayerGuid>.*)\r\nAction:\s*(?<Action>.*)\r\nServer:\s*(?<Server>.*)\r\nDate\s-\sTime:\s(?<DateTime>.*)\r\n";

            StringBuilder sb = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.IndentChars = Convert.ToString((char) Keys.Tab); 
            settings.OmitXmlDeclaration = true;

            writer = XmlWriter.Create(sb, settings);
            writer.WriteStartElement("Players");

            Int16 countme;

            foreach (Match match in Regex.Matches(rawdata, pattern))
            {
                writer.WriteElementString("Admin", match.Value.ToString());
                //writer.WriteElementString("PlayerName", match.Item("PlayerName"));
                //writer.WriteElementString("PlayerIP", match.Groups.Item("PlayerIP").Value);
                //writer.WriteElementString("PlayerGuid", match.Groups.Item("PlayerGuid").Value);
                //writer.WriteElementString("Action", match.Groups.Item("Action").Value);
                //writer.WriteElementString("Server", match.Groups.Item("Server").Value);
                //writer.WriteElementString("DateTime", match.Groups.Item("DateTime").Value);
            }

            writer.WriteEndElement();
            writer.Flush();
            writer.Close();

            richTextBox1.Text = sb.ToString();

        }

which then will be outputted like this

<Players>
    <Admin>adminbob </Admin>
    <PlayerName>ilikecabbage </PlayerName>
    <PlayerIP>NA </PlayerIP>
    <PlayerGuid>EA_70001212414521154521 </PlayerGuid>
    <Action>kick </Action>
    <Server>gameserver01 </Server>
    <DateTime>01/02/2013 - 23:24:19 </DateTime>
</Players>

never mind i solved it :d

i replaced

writer.WriteElementString("Admin", match.Value.ToString());

with

writer.WriteElementString("Admin", match.Groups.[1].Value);

thanks

This question has already been answered. Start a new discussion instead.