[xsde-users] hello example parser with std

Boris Kolpackov boris at codesynthesis.com
Wed Jul 24 03:41:24 EDT 2013


Hi Maxim,

maxim maxim <look2006il at gmail.com> writes:

>  std::string contents;
>  std::ifstream in("hello.xml", std::ios::in | std::ios::binary);
>   if (in)
>   {
>     in.seekg(0, std::ios::end);
>     contents.resize(in.tellg());
>     in.seekg(0, std::ios::beg);
>     in.read(&contents[0], contents.size());
>     in.close();
>   }
> doc_p.parse (contents);

If 

doc_p.parse ("hello.xml");

treats its argument as a file name, what do you think this call will
treat it as?

std::string s;
...
doc_p.parse (s);

I think it is pretty clear it will still treat it as a file name
(no, calling it 'contents' doesn't help).

If you want to parse a chunk of memory, you can do something like
this:

std::string s;
...
doc_p.parse (s.c_str (), s.size (), true);

See documentation for more information.

Boris



More information about the xsde-users mailing list