[Quickfix-developers] toXML function for 'special XML characters'
Brought to you by:
orenmnero
From: Van G. E. (K. 2) <edd...@cr...> - 2004-09-11 00:46:59
|
Hi Oren, after receiving a message in the Fixengine I use the toXML function to obtain the XML version of the message and then perform XSLT to transform to our internal format. for some special XML characters I had to add a bit of code in the Message.cpp to transform & in & < in < " in " otherwise the generated XML is not OK. <field name="Text" number="58" value="PRICE < 100"/> should be <field name="Text" number="58" value="PRICE < 100"/> is this somthing that you would want to put in the base quickfix release ? Rgds, Eddy std::string Message::toXMLFields(const FieldMap& fields, int space) const { QF_STACK_PUSH(Message::toXMLFields) std::stringstream stream; FieldMap::iterator i; std::string name; for(i = fields.begin(); i != fields.end(); ++i) { int field = i->first; std::string value = i->second.getString(); ********************* size_t lookHere = 0; size_t foundHere; while ((foundHere = value.find("&",lookHere)) != std::string::npos) { value.replace(foundHere, 1, "&"); lookHere = foundHere + 5; } lookHere = 0; while ((foundHere = value.find("<",lookHere)) != std::string::npos) { value.replace(foundHere, 1, "<"); lookHere = foundHere + 4; } lookHere = 0; while ((foundHere = value.find('"',lookHere)) != std::string::npos) { value.replace(foundHere, 1, """); lookHere = foundHere + 6; } ****************** |