D
Dave
All the examples i've found using XmlSerializer work with one time
serialization / deserialization of objects... or one time
serialization / deserialization of collection of objects.
I need to be able to keep a file stream open, and just serialize
(IrcMessage) objects as they come into my server, then eventually have
some other process deserialize the accumulated (IrcMessage) objects.
the problem is, every time i call:
StreamWriter messageWriter = new
StreamWriter(_logFileStream, Encoding.ASCII);
XmlSerializer writer = new
XmlSerializer(typeof(IrcMessage));
writer.Serialize(messageWriter, ircMessage2);
where:
[Serializable]
public class IrcMessage
{
int _channelId = -1;
public int ChannelId
{
get { return _channelId; }
set { _channelId = value; }
}
string _ircMessageText = null;
public string IrcMessageText
{
get { return _ircMessageText; }
set { _ircMessageText = value; }
}
}
it causes the following output:
<?xml version="1.0" encoding="us-ascii"?>
<IrcMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ChannelId>1</ChannelId>
<IrcMessageText>103 Host irc.freenode.net resolves to:
154.35.200.44, 140.211.166.3, 140.211.166.4, 204.11.244.21,
209.177.146.34, 216.155.130.130, 213.92.8.4, 207.158.1.150,
216.165.191.52, 89.16.176.16, 64.161.254.20, 82.96.64.4</
IrcMessageText>
</IrcMessage><?xml version="1.0" encoding="us-ascii"?>
<IrcMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ChannelId>2</ChannelId>
<IrcMessageText>boohaha string</IrcMessageText>
</IrcMessage><?xml version="1.0" encoding="us-ascii"?>
<IrcMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ChannelId>1</ChannelId>
<IrcMessageText>sasdjlfsdjfsdjsfdjkfsdjksdfjksdafjk;sd;jasdf</
IrcMessageText>
</IrcMessage>
i don't want the xml version info to keep being rewritten...
when trying to deserialize:
StreamReader ircMessageReader = new
StreamReader(logFileStream);
XmlSerializer ircMessageParser = new
XmlSerializer(typeof(IrcMessage));
return
(IrcMessage)ircMessageParser.Deserialize(ircMessageReader);
i blow up with Unexpected XML declaration... trying to manually remove
the declaration from the files causes other errors.
so i'm stuck. let me know if any further clarification is needed.
thanks, dave
serialization / deserialization of objects... or one time
serialization / deserialization of collection of objects.
I need to be able to keep a file stream open, and just serialize
(IrcMessage) objects as they come into my server, then eventually have
some other process deserialize the accumulated (IrcMessage) objects.
the problem is, every time i call:
StreamWriter messageWriter = new
StreamWriter(_logFileStream, Encoding.ASCII);
XmlSerializer writer = new
XmlSerializer(typeof(IrcMessage));
writer.Serialize(messageWriter, ircMessage2);
where:
[Serializable]
public class IrcMessage
{
int _channelId = -1;
public int ChannelId
{
get { return _channelId; }
set { _channelId = value; }
}
string _ircMessageText = null;
public string IrcMessageText
{
get { return _ircMessageText; }
set { _ircMessageText = value; }
}
}
it causes the following output:
<?xml version="1.0" encoding="us-ascii"?>
<IrcMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ChannelId>1</ChannelId>
<IrcMessageText>103 Host irc.freenode.net resolves to:
154.35.200.44, 140.211.166.3, 140.211.166.4, 204.11.244.21,
209.177.146.34, 216.155.130.130, 213.92.8.4, 207.158.1.150,
216.165.191.52, 89.16.176.16, 64.161.254.20, 82.96.64.4</
IrcMessageText>
</IrcMessage><?xml version="1.0" encoding="us-ascii"?>
<IrcMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ChannelId>2</ChannelId>
<IrcMessageText>boohaha string</IrcMessageText>
</IrcMessage><?xml version="1.0" encoding="us-ascii"?>
<IrcMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ChannelId>1</ChannelId>
<IrcMessageText>sasdjlfsdjfsdjsfdjkfsdjksdfjksdafjk;sd;jasdf</
IrcMessageText>
</IrcMessage>
i don't want the xml version info to keep being rewritten...
when trying to deserialize:
StreamReader ircMessageReader = new
StreamReader(logFileStream);
XmlSerializer ircMessageParser = new
XmlSerializer(typeof(IrcMessage));
return
(IrcMessage)ircMessageParser.Deserialize(ircMessageReader);
i blow up with Unexpected XML declaration... trying to manually remove
the declaration from the files causes other errors.
so i'm stuck. let me know if any further clarification is needed.
thanks, dave