Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Loading schedule data from xmlreader (Read 6676 times)
rfeuer
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 12
Joined: Jan 16th, 2006
Loading schedule data from xmlreader
Jan 16th, 2006 at 1:01am
Print Post  
Hi,
I would like to create an xml document in memory opposed to creating a physical file because my data will be stored in a db. I have been successful in creating a xml document in memory and using the xmlreader to read the xml, but I am unable to get the loadfrom(xmlreader) method to work. In addition I did send my output from the memorystream to a file to verify my xml was valid and it loaded fine that way. I am getting a "null key exception" when trying to pass an xmlreader to the loadfrom(), and cannot figure it out why.  Am I missing something, or can you suggest a better way to load my db data into the calendar without doing it from a file?

Thanks

Rick
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Loading schedule data from xmlreader
Reply #1 - Jan 16th, 2006 at 7:42am
Print Post  
Hi,

Try calling the XmlWriter.Flush() method after using Schedule.SaveTo(XmlWriter) . That will flush any remaining unsaved XmlWriter data to the underlying MemoryStream.

The null key exception might happen if you have added item/appointment objects from your own class to the schedule. The Schedule.SaveTo method looks in a map which contains (Type, Id) pairs to know what tag to use for your objects. Use the Schedule.RegisterItemClass method to add your item class to that map.

Please let me know whether that helps.

Stoyan
  
Back to top
 
IP Logged
 
rfeuer
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 12
Joined: Jan 16th, 2006
Re: Loading schedule data from xmlreader
Reply #2 - Jan 16th, 2006 at 4:21pm
Print Post  
the registering of my items sounds like the problem, but I am confused where this would fall in place. Here is the seq of events that are occuring in my method.

1. create a xmltextwriter to write to a memorystream
2. build my xml document using the xmltextwriter obj
3. flush the xmltextwriter
4. create a xmlreader
5. use method loadfrom(xmlreader)
....get exception here.

Where would the RegisterItemClass fall in place? does it replace me creating the items with the xmltextwriter? Do you have some sample source you could send me?

Thanks

Rick
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Loading schedule data from xmlreader
Reply #3 - Jan 16th, 2006 at 4:38pm
Print Post  
You might check up the CustomEvents sample - it defines a new Item-derived class and registers it with the Schedule for serialization. RegisterItemClass must be called once for each custom class, a good place for that is the main form constructor. RegisterItemClass is a static method and you can call it like that:

Schedule.RegisterItemClass(typeof(MyClass), "myClass", 1);

The "myClass" string id is saved before serializing each item. Later, when the LoadFrom method loads items, it uses the same map to determine an instance of what class should be created according to the item id.

Stoyan
  
Back to top
 
IP Logged
 
rfeuer
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 12
Joined: Jan 16th, 2006
Re: Loading schedule data from xmlreader
Reply #4 - Jan 16th, 2006 at 5:52pm
Print Post  
Thanks,

I found a better way to do this by looking at the custom events sample. Thanks for you help!!!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint