Sign in to follow this  
ehmdjii

TinyXML print to string

Recommended Posts

hello, TinyXml has a Print() function that saves the xml to a file. but i would need the xml in my program stored in a std::string or a char* how can i do that? thanks!

Share this post


Link to post
Share on other sites
yeah, i was thinking about that, but is not that easy, since this Print() function depends on a lot of other stuff which all uses the same filepointer.

of course it would be doable, but i was looking for an easier way to just redirect the stuff that is written to the filepointer to a string.

thanks!

Share this post


Link to post
Share on other sites
because i am sending it to a server over the network. and it is discarded right after that, so i there is no need to save it to a file.

Share this post


Link to post
Share on other sites
So let me get this straight first:

- You have generated your own XML inside your application (as opposed to loading it in from a file) or have modified a loaded XML file?

- You want to send the entire thing over the network, not just a particular node?

If so, i can think of two ways to get it done:

1) Print the whole tree to a file, then send the file over the network. (pro: simple. con: slow)

2) loop through each element in the tree and print each element to a string/stream. The << and >> operators are usable on all elements (consult your documentation) (pro: faster speed. con: more code needed)

Share this post


Link to post
Share on other sites
ehmdjii,

You could write XML directly to the socket. It appears that the Print function takes in a FILE*. Sockets are ints (or, ya know, SOCKETs, if you are using Windows). In other words, they are file descriptors. If you call fdopen on a data socket, it will give you a FILE* that you can use with the Print function. It won't know the difference. ;)

Vovan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this