You sure can. All you have to do is create strings in C++. You can do this a multitude of ways. In MFC, for example, you could use the CString class, in STL, the string class. You could also use the _bstr_t for BSTR. At any rate, after you create the string, then write the string out to a file. The important things to remember is that XML has to be "Well-Formed". Unlike HTML, each opening tag must have a matching closing tag (with the exceptions of self-closing tags <tagName/>) and tags must not cross other tag boundaries. By crossing tag boundaries I mean, you can not open a tag, open a second tag and close the first tag with out first closing the second tag. For example, the following is illegal in XML:
<Tree>
<leaf>
</Tree>
</leaf>
The correct way would be:
<Tree>
<leaf>
</leaf>
</Tree>
The other important thing about XML to remember is that you can only have ONE root tag. Doing the following is illegal:
<Tree>
<leaf>
</leaf>
</Tree>
<Tree>
<leaf>
</leaf>
</Tree>
You must do this:
<Forest>
<Tree>
<leaf>
</leaf>
</Tree>
<Tree>
<leaf>
</leaf>
</Tree>
</Forest>
Adding the forest tag provides a single root tag.
Enough about XML... on to your problem. You can create a string instance like:
string s = "";
and concatenate all the XML in to it. Like:
s += "<Root><someothertag/></Root>";
and then write it to a text file.
If your xml becomes so large that one string cannot hold it all, then create mulitple strings and write each string, in succession to the file.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.