[studxml-users] Re: libstudxml: attributes with spaces are not
fully extracted with parser::attribute<T> when T is std::string
Boris Kolpackov
boris at codesynthesis.com
Wed Oct 29 13:52:07 EDT 2014
Hi Glenn,
EXT-Ehrlich, Glenn <glenn.ehrlich2 at boeing.com> 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<T> or parser::element<T> 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 <foo bar="some text"/>, 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<std::string>
> {
> 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
More information about the studxml-users
mailing list