how to convert c string to xml using standard c++?
I would like to know is there any way to generate xml schema from a c string by using stander c++? In my current application there is a server which sends comma separated string by a socket. That is cumbersome to parse date. I would like to extend this to convert this开发者_如何学Go string into a standard XML format. So that I could easily parse data from client side.
c string:- Temperature,low:20,high:30,current:24
xml:-
<temperature>
<low>20</low>
<high>30</high>
<current>24</current>
</temperature>
Please provide some link or example to study more. Thanks!
C++ doesn't have a XML parser as part of the standard library. To do this you need a 3rd party library. MSXML and Xerces are two that I have used. While Xerces is a little more cumbersome to set up I have to say it is much nicer of the two.
Basically you have two separate steps:
- Parse the String and get the information you want out of it
- Write the XML
For Step 1. I would suggest using some regular expression library, e.g. Boost.Regex.
As soon as you have the information parsed, you can simply write the XML into a string using standard streams like
std::stringstream s;
s << "<temperature><low>" << low << "</low><high>" << high << "</high>";
s << "<current>" << current << "</current>";
s << "</temperature>";
and use the resulting string with s.str()
.
精彩评论