Home » U++ Library support » U++ Core » Xmlize works only for storing
Xmlize works only for storing [message #18445] |
Wed, 01 October 2008 15:16 |
exhu
Messages: 12 Registered: April 2008 Location: Belarus
|
Promising Member |
|
|
Please, help understanding the XML serialization implemented in UPP.
This code perfectly saves the XML as intended, but does not load attribute values:
void ServData::save() {
StoreAsXMLFile(*this);
}
void ServData::load() {
LoadFromXMLFile(*this);
}
void ServData::Xmlize(XmlIO xml) {
::Xmlize(xml.Add("map"), locationMap);
}
/////////
void Xmlize(XmlIO xml, Map & locMap) {
Xmlize(xml.Add("left"), locMap.left);
Xmlize(xml.Add("right"), locMap.right);
Xmlize(xml.Add("top"), locMap.top);
Xmlize(xml.Add("bottom"), locMap.bottom);
}
void Xmlize(XmlIO xml, MapPlace & place) {
String nm;
if (xml.IsStoring())
nm = place.name;
xml.Attr("name", nm); // nm is always empty on xml.IsLoading! why?
if (xml.IsLoading())
place.name = nm;
}
|
|
|
|
Re: Xmlize works only for storing [message #18464 is a reply to message #18454] |
Thu, 02 October 2008 09:08 |
exhu
Messages: 12 Registered: April 2008 Location: Belarus
|
Promising Member |
|
|
Quote: | Why don`t you use construction from Xmlize reference sample:
|
I can't use it because STL and other simple types already defined in the program do not contain Xmlize methods which are called by the template.
Changed to:
void ServData::Xmlize(XmlIO xml) {
::Xmlize(XmlIO(xml,"map"), locationMap);
//XmlIO(xml, "magic").Attr("magic", magic);
//magic = magic;
}
/////////
void Xmlize(XmlIO xml, Map & locMap) {
xml.Attr("shopname", locMap.shopName);
Xmlize(XmlIO(xml, "left"), locMap.left);
Xmlize(XmlIO(xml,"right"), locMap.right);
Xmlize(XmlIO(xml,"top"), locMap.top);
Xmlize(XmlIO(xml,"bottom"), locMap.bottom);
}
Now it works, but it's not obvious why because both Add() method and XmlIO() constructor use & (reference) for variable argument.
Who can explain this magic? No comments at all in the library sources
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Sat May 04 16:06:07 CEST 2024
Total time taken to generate the page: 0.01541 seconds
|