XML optional field

Hi AllI would like to build a configuration file for my application in XML.The Configuration files includes also optional sectionsi.e. there might be properties that are not required to be defined by the user. If I use BOOST serialization to load this file, the XML format seems to me that forces every field of the XML field to be REQUIRED. Do you know if with Boost serialization for XML there is some mechanismallowing or handling optional Xml field? Kind RegardsManu _________________________________________________________________ Tutto il mondo MSN a portata di clic! http://toolbar.msn.com/overview.aspx?loc=it-it

On Tue, Sep 23, 2008 at 02:56, Emanuele Rocci
I would like to build a configuration file for my application in XML. The Configuration files includes also optional sections i.e. there might be properties that are not required to be defined by the user.
If I use BOOST serialization to load this file, the XML format seems to me that forces every field of the XML field to be REQUIRED.
Do you know if with Boost serialization for XML there is some mechanism allowing or handling optional Xml field?
For something that a user is supposed to be able to edit, Boost.Serialization is usually not the correct choice (afaik). Have you considered the boost.program_options library? http://www.boost.org/libs/program_options HTH, ~ Scott

Thanks! Mn
Date: Tue, 23 Sep 2008 09:56:27 -0400> From: me22.ca+boost@gmail.com> To: boost-users@lists.boost.org> Subject: Re: [Boost-users] XML optional field> > On Tue, Sep 23, 2008 at 02:56, Emanuele Rocci
wrote:> >> > I would like to build a configuration file for my application in XML.> > The Configuration files includes also optional sections> > i.e. there might be properties that are not required to be> > defined by the user.> >> > If I use BOOST serialization to load this file, the XML format seems to me> > that forces every field of the XML field to be REQUIRED.> >> > Do you know if with Boost serialization for XML there is some mechanism> > allowing or handling optional Xml field?> >> > For something that a user is supposed to be able to edit,> Boost.Serialization is usually not the correct choice (afaik).> > Have you considered the boost.program_options library?> http://www.boost.org/libs/program_options> > HTH,> ~ Scott> _______________________________________________> Boost-users mailing list> Boost-users@lists.boost.org> http://lists.boost.org/mailman/listinfo.cgi/boost-users
Comunica, gioca e divertiti con i tuoi amici su Messenger! http://www.messenger.it

Hi All I am using a boost::variant. If I have boost::variant< std::string, double, int > aVariable for example, do you know a way to test -what types are supported i.e. some test telling me that aVariable handles string, double and int -how many types are supported i.e. 3 in this example Kind Regards _________________________________________________________________ Cerchi un locale per la serata? Chiedilo a Live Maps! http://maps.live.it/

AMDG Emanuele Rocci wrote:
If I have boost::variant< std::string, double, int > aVariable for example, do you know a way to test -what types are supported i.e. some test telling me that aVariable handles string, double and int -how many types are supported i.e. 3 in this example
"The bounded types of the variant are exposed via the nested typedef types, which is an MPL-compatible Sequence containing the set of types that must be handled by any visitor to the variant." In Christ, Steven Watanabe

I don't think boost serialization is a good option to loaded an externally defined file.
consider a spirit based xml parser.
Robert Ramey
"Emanuele Rocci"

Could this be an option for you "Arabica XML Toolkit"? http://www.jezuk.co.uk/cgi-bin/view/arabica

Hello, I have the following regex: sregex sig_re = "@rem {" >>(sig_= -*_)>> "}, " >> (vbp_= -*_) >> _ln; which I am trying to use to match the last line of the following string. The string is read in from a file. xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y @rem c:\foo\somefile.txt files: 4 @rem {0xffffffff, SOMETYPEDEF, ""}, //c:\foo\somefile.txt When I call: sregex_iterator cur(file_contents.begin(), file_contents.end(), sig_re); however, I get an assertion: Assertion failed: !s0.matched, file c:\code\boost-trunk\boost\xpressive\detail\core\matcher\end_matcher.hpp, line 37 Originally I had wanted to match the varying parts of the above file but I kept getting the above assertion, so I decided to take the easy way and just match the last line of the file, but still got the assertion. My original regex was this: mark_tag file_(0), vbp_(1), sig_(2); sregex files_re = "xcopy" >> *_ >> "/Y" >> _n; sregex vbp_re = "@rem " >> -*_ >> " files: " >> repeat<1, 4>(_d) >> _ln; sregex sig_re = "@rem {" >> -*_>> "}, " >> -*_ >> _ln; sregex file_re = (file_=(files_re)) >> (vbp_=(vbp_re)) >> (sig_=(sig_re)); But that failed. Which leads me to my second question, with the above file, I would like an xpressive regex that will match the 3 portions of the file so that I have: a. An array of sub_match containing the following 4 strings xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y b. A sub_match with the following string: @rem c:\foo\somefile.txt files: 4 c. A sub_match with the following string: @rem {0xffffffff, SOMETYPEDEF, ""}, //c:\foo\somefile.txt Thanks for the help. Josh

Raindog wrote:
Hello,
I have the following regex:
sregex sig_re = "@rem {" >>(sig_= -*_)>> "}, " >> (vbp_= -*_) >> _ln;
which I am trying to use to match the last line of the following string. The string is read in from a file.
xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y @rem c:\foo\somefile.txt files: 4 @rem {0xffffffff, SOMETYPEDEF, ""}, //c:\foo\somefile.txt
When I call:
sregex_iterator cur(file_contents.begin(), file_contents.end(), sig_re);
however, I get an assertion:
Assertion failed: !s0.matched, file c:\code\boost-trunk\boost\xpressive\detail\core\matcher\end_matcher.hpp, line 37
Originally I had wanted to match the varying parts of the above file but I kept getting the above assertion, so I decided to take the easy way and just match the last line of the file, but still got the assertion. My original regex was this:
mark_tag file_(0), vbp_(1), sig_(2); sregex files_re = "xcopy" >> *_ >> "/Y" >> _n; sregex vbp_re = "@rem " >> -*_ >> " files: " >> repeat<1, 4>(_d) >> _ln; sregex sig_re = "@rem {" >> -*_>> "}, " >> -*_ >> _ln; sregex file_re = (file_=(files_re)) >> (vbp_=(vbp_re)) >> (sig_=(sig_re));
But that failed. Which leads me to my second question, with the above file, I would like an xpressive regex that will match the 3 portions of the file so that I have:
a. An array of sub_match containing the following 4 strings xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y
b. A sub_match with the following string:
So I did a bit more digging and the following gives me everything I want except for the capture group where I capture the list of 4 xcopy lines. sregex files_re = "xcopy" >> -*_ >> "/Y" >> _n; sregex vbp_re = "@rem " >> -*_ >> " files: " >> repeat<1, 4>(_d) >> _ln; sregex sig_re = "@rem {" >> -*_>> "}, " >> -*_ >> _ln; sregex file_re = *files_re >> (vbp_=vbp_re) >> (sig_=sig_re); Which lets me complete my immediate task but still leaves me curious about how I would go about capturing the 4 xcopy lines. Thanks, Josh

Raindog wrote:
Hello,
I have the following regex:
sregex sig_re = "@rem {" >>(sig_= -*_)>> "}, " >> (vbp_= -*_) >> _ln;
which I am trying to use to match the last line of the following string. The string is read in from a file.
xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y @rem c:\foo\somefile.txt files: 4 @rem {0xffffffff, SOMETYPEDEF, ""}, //c:\foo\somefile.txt
When I call:
sregex_iterator cur(file_contents.begin(), file_contents.end(), sig_re);
however, I get an assertion:
Assertion failed: !s0.matched, file c:\code\boost-trunk\boost\xpressive\detail\core\matcher\end_matcher.hpp, line 37
I cannot reproduce your error. The following works (doesn't assert) for me: mark_tag sig_(1), vbp_(2); sregex sig_re = "@rem {" >>(sig_= -*_)>> "}, " >> (vbp_= -*_) >> _ln; std::string file_contents = "xcopy \"foo\" \"foo3.bat\" /Y\n" "xcopy \"foo\" \"foo3.bat\" /Y\n" "xcopy \"foo\" \"foo3.bat\" /Y\n" "xcopy \"foo\" \"foo3.bat\" /Y\n" "@rem c:\\foo\\somefile.txt files: 4\n" "@rem {0xffffffff, SOMETYPEDEF, \"\"}, //c:\\foo\\somefile.txt\n"; sregex_iterator cur(file_contents.begin(), file_contents.end(), sig_re); Please post complete source that reproduces the problem. Thanks. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric Niebler wrote:
Raindog wrote:
Hello,
I have the following regex:
sregex sig_re = "@rem {" >>(sig_= -*_)>> "}, " >> (vbp_= -*_) >> _ln;
which I am trying to use to match the last line of the following string. The string is read in from a file.
xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y xcopy "foo" "foo3.bat" /Y @rem c:\foo\somefile.txt files: 4 @rem {0xffffffff, SOMETYPEDEF, ""}, //c:\foo\somefile.txt
When I call:
sregex_iterator cur(file_contents.begin(), file_contents.end(), sig_re);
however, I get an assertion:
Assertion failed: !s0.matched, file c:\code\boost-trunk\boost\xpressive\detail\core\matcher\end_matcher.hpp, line 37
I cannot reproduce your error. The following works (doesn't assert) for me:
mark_tag sig_(1), vbp_(2); sregex sig_re = "@rem {" >>(sig_= -*_)>> "}, " >> (vbp_= -*_) >> _ln;
std::string file_contents = "xcopy \"foo\" \"foo3.bat\" /Y\n" "xcopy \"foo\" \"foo3.bat\" /Y\n" "xcopy \"foo\" \"foo3.bat\" /Y\n" "xcopy \"foo\" \"foo3.bat\" /Y\n" "@rem c:\\foo\\somefile.txt files: 4\n" "@rem {0xffffffff, SOMETYPEDEF, \"\"}, //c:\\foo\\somefile.txt\n";
sregex_iterator cur(file_contents.begin(), file_contents.end(), sig_re);
Please post complete source that reproduces the problem. Thanks.
mark_tag file_(0), vbp_(1), sig_(2); sregex files_re = "xcopy" >> -*_ >> "/Y" >> _n; sregex vbp_re = "@rem " >> -*_ >> " files: " >> repeat<1, 4>(_d) >> _ln; sregex sig_re = "@rem {" >> -*_>> "}, " >> *~_ln; //Combine above regexes to allow for only one search through the file. sregex whole_string_re = (file_=*files_re) >> (vbp_=vbp_re) >> (sig_=sig_re); sregex_iterator cur(file_contents.begin(), file_contents.end(), whole_string_re); sregex_iterator end; What I was trying to do was instead of searching for matches multiple times, I decided to combine files_re, vbp_re and sig_re into 1 regex and just do 1 search. That was when I had the assertion. If I change (file_=*files_re) >> to *files_re >> Then it works, but I don't have the capture group I wanted.

Raindog wrote:
mark_tag file_(0), vbp_(1), sig_(2);
The problem is here^^^
sregex files_re = "xcopy" >> -*_ >> "/Y" >> _n; sregex vbp_re = "@rem " >> -*_ >> " files: " >> repeat<1, 4>(_d) >> _ln; sregex sig_re = "@rem {" >> -*_>> "}, " >> *~_ln;
Sub-match 0 is "special". It refers to the whole match, not to an individual sub-match. Change that line to: mark_tag file_(1), vbp_(2), sig_(3); ... and that should fix your problem. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric Niebler wrote:
Raindog wrote:
mark_tag file_(0), vbp_(1), sig_(2);
The problem is here^^^
sregex files_re = "xcopy" >> -*_ >> "/Y" >> _n; sregex vbp_re = "@rem " >> -*_ >> " files: " >> repeat<1, 4>(_d)
_ln; sregex sig_re = "@rem {" >> -*_>> "}, " >> *~_ln;
Sub-match 0 is "special". It refers to the whole match, not to an individual sub-match. Change that line to:
mark_tag file_(1), vbp_(2), sig_(3);
... and that should fix your problem.
Ok, that works, thanks! Secondly, I'm using the nested_results() function but am puzzled as to how to distinguish between which regex was responsible for creating the nested result. Is there a way to get only the nested results that files_re matched? Thanks!

Raindog wrote:
Secondly, I'm using the nested_results() function but am puzzled as to how to distinguish between which regex was responsible for creating the nested result. Is there a way to get only the nested results that files_re matched?
http://tinyurl.com/5x54yq :-) -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (7)
-
Emanuele Rocci
-
Eric Niebler
-
p
-
Raindog
-
Robert Ramey
-
Scott McMurray
-
Steven Watanabe