[studxml-users] libstudxml: attributes with spaces are not fully extracted with parser::attribute<T> when T is std::string

EXT-Ehrlich, Glenn glenn.ehrlich2 at boeing.com
Wed Oct 29 12:33:22 EDT 2014


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<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".

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.

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 at boeing.com<mailto:glenn.ehrlich2 at boeing.com>





More information about the studxml-users mailing list