1

Can someone give me an example of serialization/deseralization using the Boost library? I am working in c++/ubuntu 9.1

I have the class

class x
{
public:
    x();

    std::string name;
    std::string surname;
};

How can I create XML <1.0...> id: <name>..<surname> using boost serialization? Or is there another way to do it?

2 Answers 2

1

boost serialization will build its own XML schema which is not modifiable. Serialization is for serialization not reading/writing random XML.

Sign up to request clarification or add additional context in comments.

Comments

0

boost is overkill for such a trivial example... I mean, all you need is

friend std::ostream& (std::ostream& str, x const & cData)
{
  return str << "<...><name>" << cData.name << "</name><surname>" << cData.surname << "</surname></...>";
}

4 Comments

This looks like a direct route to producing invalid XML, as it doesn't entitize the data. I.e., what happens if either string contains a <?
@ildjarn, the point I'm trying to make is that sometimes you don't need the overhead... Anyways - is there any name on this planet which has a >/< or & in it? How would you even say it? That's just plain daft! Surely any input mechanism will have validated the data by this point anyway.
Uncommon, sure, but in the USA at least it's certainly legal to have special punctuation in one's name.
@ildjarn, a > or < ? wow... folks across the pond certainly are different ;) Anyways, it's a suggestion to look at a more lightweight approach...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.