From glenn.ehrlich2 at boeing.com Wed Oct 29 12:33:22 2014 From: glenn.ehrlich2 at boeing.com (EXT-Ehrlich, Glenn) Date: Wed Oct 29 13:14:36 2014 Subject: [studxml-users] libstudxml: attributes with spaces are not fully extracted with parser::attribute when T is std::string Message-ID: Hi, First off, I'd like to say how great libstudxml is. It's made our xml parsing quite a bit better than using the alternatives. Anyway.... There's a minor "defect" with the way std::string is handled with parser::attribute or parser::element when T is std::string. Since the default implementation of these uses operator>> to pull the value out of the text, if the text has multiple spaces in it, the operator>> will stop at the first space. Thus when parsing something like , if bar is going into a std::string variable, it's text will be "some" instead of "some text". I've fixed this in our version of the code by making this mod to value-traits: template <> struct LIBSTUDXML_EXPORT default_value_traits { static std::string parse (std::string s, const parser&) { return s; } }; I don't implement serialize() because we don't use it and I'd like to think that the default implementation of serialize() would work, so this may not be a complete fix. By the way, I work for Jeff Garland and he said to mention him, as you guys have met several times. He's the one who suggested using libstudxml. Glenn Ehrlich glenn.ehrlich2@boeing.com From boris at codesynthesis.com Wed Oct 29 13:52:07 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 29 13:59:18 2014 Subject: [studxml-users] Re: libstudxml: attributes with spaces are not fully extracted with parser::attribute when T is std::string In-Reply-To: References: Message-ID: Hi Glenn, EXT-Ehrlich, Glenn writes: > First off, I'd like to say how great libstudxml is. It's made our xml > parsing quite a bit better than using the alternatives. Glad to hear that, thanks! > There's a minor "defect" with the way std::string is handled with > parser::attribute or parser::element when T is std::string. > Since the default implementation of these uses operator>> to pull > the value out of the text, if the text has multiple spaces in it, > the operator>> will stop at the first space. Thus when parsing > something like , if bar is going into a > std::string variable, it's text will be "some" instead of "some text". Yes, you are right. Thanks for the bug report! > I've fixed this in our version of the code by making this mod to > value-traits: > > template <> > struct LIBSTUDXML_EXPORT default_value_traits > { > static std::string > parse (std::string s, const parser&) > { > return s; > } > }; > > I don't implement serialize() because we don't use it and I'd like > to think that the default implementation of serialize() would work, > so this may not be a complete fix. I think serialize() that simply returns the passed string will be at least significantly faster. I've added the fix that specializes both parse() and serialize(), as well as the test: http://scm.codesynthesis.com/?p=libstudxml/libstudxml.git;a=commit;h=7275dc4d919b0cb6f8713d0b4a9a2b507051cded > By the way, I work for Jeff Garland and he said to mention him, as you > guys have met several times. He's the one who suggested using libstudxml. Yes, Jeff was at the C++Now 2014 talk where I introduced libstudxml. Please pass my regards to him when you have a chance. Thanks, Boris