Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't boost::serialization check for tag names in XML archives?
    text
    copied!<p>I'm starting to use boost::serialization on XML archives. I can produce and read data, but when I hand-modify the XML and interchange two tags, it "fails to fail" (i.e. it proceeds happily).</p> <p>Here's a small, self-complete example showing what I see:</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;boost/archive/xml_oarchive.hpp&gt; #include &lt;boost/archive/xml_iarchive.hpp&gt; #include &lt;boost/serialization/nvp.hpp&gt; #include &lt;boost/serialization/split_member.hpp&gt; using namespace std; int main (void) { boost::archive::xml_oarchive oa (cout); static const string producer = "XXX", version = "0.0.1"; oa &lt;&lt; boost::serialization::make_nvp ("producer", producer); oa &lt;&lt; boost::serialization::make_nvp ("producer_version", version); } </code></pre> <p>This writes XML to standard output, which contains:</p> <pre><code>&lt;producer&gt;XXX&lt;/producer&gt; &lt;producer_version&gt;0.0.1&lt;/producer_version&gt; </code></pre> <p>Now, I replace all the code in the main function with a reader:</p> <pre><code> boost::archive::xml_iarchive ia (cin); string producer, version; ia &gt;&gt; boost::serialization::make_nvp ("producer", producer); ia &gt;&gt; boost::serialization::make_nvp ("producer_version", version); cout &lt;&lt; producer &lt;&lt; " " &lt;&lt; version &lt;&lt; endl; </code></pre> <p>which works as expected when fed the previous output (outputs "XXX 0.0.1"). If, however, I feed it XML in which I changed the order of the two lines "producer" and "producer_version", it still runs and outputs "0.0.1 XXX".</p> <p>Thus, it fails to recognize that the tags don't have the expected names, and just proceed. I would have expected it to thrown a <code>xml_archive_parsing_error</code> exception, as indicated in <a href="http://www.boost.org/doc/libs/1_42_0/libs/serialization/doc/exceptions.html#xml_archive_tag_mismatch" rel="nofollow noreferrer">the doc</a>.</p> <p>Does someone here have experience with that? What I am doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload