Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
XMLUtils Class Reference

XML Utilities Class. More...

#include <ored/utilities/xmlutils.hpp>

+ Collaboration diagram for XMLUtils:

Static Public Member Functions

static void checkNode (XMLNode *n, const string &expectedName)
 
static XMLNodeaddChild (XMLDocument &doc, XMLNode *n, const string &name)
 
static void addChild (XMLDocument &doc, XMLNode *n, const string &name, const string &value)
 
static void addChildAsCdata (XMLDocument &doc, XMLNode *n, const string &name, const string &value)
 
static void addChild (XMLDocument &doc, XMLNode *n, const string &name, const string &value, const string &attrName, const string &attr)
 
static void addChild (XMLDocument &doc, XMLNode *n, const string &name, const string &value, const vector< string > &attrNames, const vector< string > &attrs)
 
static void addChild (XMLDocument &doc, XMLNode *n, const string &name, const char *value)
 
static void addChild (XMLDocument &doc, XMLNode *n, const string &name, Real value)
 
static void addChild (XMLDocument &doc, XMLNode *n, const string &name, int value)
 
static void addChild (XMLDocument &doc, XMLNode *n, const string &name, bool value)
 
static void addChild (XMLDocument &doc, XMLNode *n, const string &name, const Period &value)
 
template<class T >
static void addGenericChild (XMLDocument &doc, XMLNode *n, const char *name, const T &value)
 Adds <Name>p1,p2,p3</Name> More...
 
template<class T >
static void addGenericChildAsList (XMLDocument &doc, XMLNode *n, const string &name, const vector< T > &values, const string &attrName="", const string &attr="")
 
template<class T = string>
static void addChildren (XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values)
 
static void addChild (XMLDocument &doc, XMLNode *n, const string &name, const vector< Real > &values)
 Adds <Name>v1,v2,v3</Name> - the inverse of getChildrenValuesAsDoublesCompact. More...
 
template<class T = string>
static void addChildrenWithAttributes (XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values, const string &attrName, const vector< string > &attrs)
 
template<class T = string>
static void addChildrenWithAttributes (XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values, const vector< string > &attrNames, const vector< vector< string > > &attrs)
 
template<class T = string>
static void addChildrenWithOptionalAttributes (XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values, const string &attrName, const vector< string > &attrs)
 
template<class T = string>
static void addChildrenWithOptionalAttributes (XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values, const vector< string > &attrNames, const vector< vector< string > > &attrs)
 
static void addChildren (XMLDocument &doc, XMLNode *n, const string &names, const string &name, const string &firstName, const string &secondName, const map< string, string > &values)
 
static string getChildValue (XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
 
static Real getChildValueAsDouble (XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
 
static int getChildValueAsInt (XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
 
static bool getChildValueAsBool (XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
 
static Period getChildValueAsPeriod (XMLNode *node, const string &name, bool mandatory=false, const QuantLib::Period &defaultValue=0 *QuantLib::Days)
 
static vector< string > getChildrenValues (XMLNode *node, const string &names, const string &name, bool mandatory=false)
 
static vector< string > getChildrenValuesWithAttributes (XMLNode *node, const string &names, const string &name, const string &attrName, vector< string > &attrs, bool mandatory=false)
 
static vector< string > getChildrenValuesWithAttributes (XMLNode *node, const string &names, const string &name, const vector< string > &attrNames, const vector< std::reference_wrapper< vector< string > > > &attrs, bool mandatory=false)
 
template<class T >
static vector< T > getChildrenValuesWithAttributes (XMLNode *node, const string &names, const string &name, const string &attrName, vector< string > &attrs, const std::function< T(string)> parser, bool mandatory=false)
 
template<class T >
static vector< T > getChildrenValuesWithAttributes (XMLNode *node, const string &names, const string &name, const vector< string > &attrNames, const vector< std::reference_wrapper< vector< string > > > &attrs, const std::function< T(string)> parser, bool mandatory=false)
 
static vector< Real > getChildrenValuesAsDoubles (XMLNode *node, const string &names, const string &name, bool mandatory=false)
 
static vector< Real > getChildrenValuesAsDoublesCompact (XMLNode *node, const string &name, bool mandatory=false)
 
static vector< Period > getChildrenValuesAsPeriods (XMLNode *node, const string &name, bool mandatory=false)
 
static vector< string > getChildrenValuesAsStrings (XMLNode *node, const string &name, bool mandatory=false)
 
static map< string, string > getChildrenValues (XMLNode *node, const string &names, const string &name, const string &firstName, const string &secondName, bool mandatory=false)
 
static map< string, string > getChildrenAttributesAndValues (XMLNode *parent, const string &names, const string &attributeName, bool mandatory=false)
 
static XMLNodegetChildNode (XMLNode *n, const string &name="")
 
static XMLNodelocateNode (XMLNode *n, const string &name="")
 
static void appendNode (XMLNode *parent, XMLNode *child)
 
static void addAttribute (XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
 
static string getAttribute (XMLNode *node, const string &attrName)
 
static vector< XMLNode * > getChildrenNodes (XMLNode *node, const string &name)
 Returns all the children with a given name. More...
 
static vector< XMLNode * > getChildrenNodesWithAttributes (XMLNode *node, const string &names, const string &name, const string &attrName, vector< string > &attrs, bool mandatory=false)
 
static vector< XMLNode * > getChildrenNodesWithAttributes (XMLNode *node, const string &names, const string &name, const vector< string > &attrNames, const vector< std::reference_wrapper< vector< string > > > &attrs, bool mandatory=false)
 
static string getNodeName (XMLNode *n)
 Get and set a node's name. More...
 
static void setNodeName (XMLDocument &doc, XMLNode *node, const string &name)
 
static XMLNodegetNextSibling (XMLNode *node, const string &name="")
 Get a node's next sibling node. More...
 
static string getNodeValue (XMLNode *node)
 Get a node's value. More...
 
static vector< Real > getNodeValueAsDoublesCompact (XMLNode *node)
 Get a node's compact values as vector of doubles. More...
 
static string toString (XMLNode *node)
 Write a node out as a string. More...
 
static string convertToString (const Real value)
 
template<class T >
static string convertToString (const T &value)
 

Detailed Description

XML Utilities Class.

Definition at line 119 of file xmlutils.hpp.

Member Function Documentation

◆ checkNode()

void checkNode ( XMLNode n,
const string &  expectedName 
)
static

Definition at line 175 of file xmlutils.cpp.

175 {
176 QL_REQUIRE(node, "XML Node is NULL (expected " << expectedName << ")");
177 QL_REQUIRE(node->name() == expectedName,
178 "XML Node name " << node->name() << " does not match expected name " << expectedName);
179}
+ Here is the caller graph for this function:

◆ addChild() [1/10]

XMLNode * addChild ( XMLDocument doc,
XMLNode n,
const string &  name 
)
static

Definition at line 181 of file xmlutils.cpp.

181 {
182 QL_REQUIRE(parent, "XML Parent Node is NULL (adding Child " << name << ")");
183 XMLNode* node = doc.allocNode(name);
184 parent->insert_node(0, node);
185 return node;
186}
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
string name
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addChild() [2/10]

void addChild ( XMLDocument doc,
XMLNode n,
const string &  name,
const string &  value 
)
static

Definition at line 192 of file xmlutils.cpp.

192 {
193 if (value.empty()) {
194 addChild(doc, n, name);
195 } else {
196 XMLNode* node = doc.allocNode(name, value);
197 QL_REQUIRE(n, "XML Node is NULL (adding " << name << ")");
198 n->insert_node(0, node);
199 }
200}
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
SafeStack< ValueType > value
+ Here is the call graph for this function:

◆ addChildAsCdata()

void addChildAsCdata ( XMLDocument doc,
XMLNode n,
const string &  name,
const string &  value 
)
static

Definition at line 202 of file xmlutils.cpp.

202 {
203 if (value.empty()) {
204 addChild(doc, n, name);
205 } else {
206 QL_REQUIRE(n, "XML Node is NULL (adding " << name << ")");
207 XMLNode* node = doc.allocNode(name);
208 n->insert_node(0, node);
209 XMLNode* cdata_node = doc.doc()->allocate_node(node_cdata);
210 cdata_node->value(doc.allocString(value));
211 QL_REQUIRE(cdata_node, "Failed to allocate cdata node for " << name);
212 node->insert_node(0, cdata_node);
213 }
214}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addChild() [3/10]

void addChild ( XMLDocument doc,
XMLNode n,
const string &  name,
const string &  value,
const string &  attrName,
const string &  attr 
)
static

Definition at line 216 of file xmlutils.cpp.

217 {
218 if (!attrName.empty() || !attr.empty()) {
219 addChild(doc, n, name, value, std::vector<string>{attrName}, std::vector<string>{attr});
220 } else {
221 addChild(doc, n, name, value, std::vector<string>{}, std::vector<string>{});
222 }
223}
+ Here is the call graph for this function:

◆ addChild() [4/10]

void addChild ( XMLDocument doc,
XMLNode n,
const string &  name,
const string &  value,
const vector< string > &  attrNames,
const vector< string > &  attrs 
)
static

Definition at line 225 of file xmlutils.cpp.

226 {
227 QL_REQUIRE(attrNames.size() == attrs.size(), "The size of attrNames should be the same as the size of attrs.");
228 XMLNode* node;
229 if (value.empty()) {
230 node = addChild(doc, n, name);
231 } else {
232 node = doc.allocNode(name, value);
233 QL_REQUIRE(n, "XML Node is NULL (adding " << name << ")");
234 n->insert_node(0, node);
235 }
236 for (Size i = 0; i < attrNames.size(); ++i) {
237 XMLUtils::addAttribute(doc, node, attrNames[i], attrs[i]);
238 }
239}
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
Definition: xmlutils.cpp:412
+ Here is the call graph for this function:

◆ addChild() [5/10]

void addChild ( XMLDocument doc,
XMLNode n,
const string &  name,
const char *  value 
)
static

Definition at line 188 of file xmlutils.cpp.

188 {
189 addChild(doc, n, name, string(value));
190}
+ Here is the call graph for this function:

◆ addChild() [6/10]

void addChild ( XMLDocument doc,
XMLNode n,
const string &  name,
Real  value 
)
static

Definition at line 241 of file xmlutils.cpp.

241 {
243}
static string convertToString(const Real value)
Definition: xmlutils.cpp:620
+ Here is the call graph for this function:

◆ addChild() [7/10]

void addChild ( XMLDocument doc,
XMLNode n,
const string &  name,
int  value 
)
static

Definition at line 245 of file xmlutils.cpp.

245 {
246 addChild(doc, n, name, std::to_string(value));
247}
+ Here is the call graph for this function:

◆ addChild() [8/10]

void addChild ( XMLDocument doc,
XMLNode n,
const string &  name,
bool  value 
)
static

Definition at line 249 of file xmlutils.cpp.

249 {
250 string s = value ? "true" : "false";
251 addChild(doc, n, name, s);
252}
+ Here is the call graph for this function:

◆ addChild() [9/10]

void addChild ( XMLDocument doc,
XMLNode n,
const string &  name,
const Period &  value 
)
static

Definition at line 254 of file xmlutils.cpp.

254 {
256}
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

◆ addGenericChild()

static void addGenericChild ( XMLDocument doc,
XMLNode n,
const char *  name,
const T &  value 
)
static

Adds <Name>p1,p2,p3</Name>

Definition at line 137 of file xmlutils.hpp.

137 {
138 std::ostringstream oss;
139 oss << value;
140 addChild(doc, n, name, oss.str());
141 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addGenericChildAsList()

static void addGenericChildAsList ( XMLDocument doc,
XMLNode n,
const string &  name,
const vector< T > &  values,
const string &  attrName = "",
const string &  attr = "" 
)
static

Definition at line 144 of file xmlutils.hpp.

145 {
146 std::ostringstream oss;
147 if (values.size() == 0) {
148 oss << "";
149 } else {
150 oss << values[0];
151 for (Size i = 1; i < values.size(); i++) {
152 oss << ", " << values[i];
153 }
154 }
155 addChild(doc, n, name, oss.str(), attrName, attr);
156 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addChildren() [1/2]

void addChildren ( XMLDocument doc,
XMLNode n,
const string &  names,
const string &  name,
const vector< T > &  values 
)
static

Definition at line 502 of file xmlutils.cpp.

503 {
504 XMLNode* node = addChild(doc, parent, names);
505 for (Size i = 0; i < values.size(); i++)
506 addChild(doc, node, name, values[i]);
507}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addChild() [10/10]

void addChild ( XMLDocument doc,
XMLNode n,
const string &  name,
const vector< Real > &  values 
)
static

Adds <Name>v1,v2,v3</Name> - the inverse of getChildrenValuesAsDoublesCompact.

Definition at line 258 of file xmlutils.cpp.

258 {
259 vector<string> strings(values.size());
260 std::transform(values.begin(), values.end(), strings.begin(), [](Real x) { return convertToString(x); });
261 addChild(doc, parent, name, boost::algorithm::join(strings, ","));
262}
+ Here is the call graph for this function:

◆ addChildrenWithAttributes() [1/2]

void addChildrenWithAttributes ( XMLDocument doc,
XMLNode n,
const string &  names,
const string &  name,
const vector< T > &  values,
const string &  attrName,
const vector< string > &  attrs 
)
static

Definition at line 510 of file xmlutils.cpp.

511 {
512 addChildrenWithAttributes(doc, parent, names, name, values, vector<string>{attrName},
513 vector<vector<string>>{attrs});
514}
static void addChildrenWithAttributes(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values, const string &attrName, const vector< string > &attrs)
Definition: xmlutils.cpp:510
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addChildrenWithAttributes() [2/2]

void addChildrenWithAttributes ( XMLDocument doc,
XMLNode n,
const string &  names,
const string &  name,
const vector< T > &  values,
const vector< string > &  attrNames,
const vector< vector< string > > &  attrs 
)
static

Definition at line 517 of file xmlutils.cpp.

519 {
520 QL_REQUIRE(attrNames.size() == attrs.size(),
521 "attrNames size (" << attrNames.size() << ") must match attrs size (" << attrs.size() << ")");
522 if (values.size() > 0) {
523 for (auto const& attr : attrs) {
524 QL_REQUIRE(values.size() == attr.size(), "Values / Attribute vector size mismatch");
525 }
526 QL_REQUIRE(parent, "XML Node is null (Adding " << names << ")");
527 XMLNode* node = addChild(doc, parent, names);
528 for (Size i = 0; i < values.size(); i++) {
529 XMLNode* c = doc.allocNode(name, convertToString(values[i]));
530 QL_REQUIRE(c, "XML AllocNode failure (" << name << ")");
531 QL_REQUIRE(node, "XML Node is NULL (" << name << ")");
532 node->insert_node(0, c);
533 for (Size j = 0; j < attrs.size(); ++j) {
534 if (attrs[j][i] != "")
535 addAttribute(doc, c, attrNames[j], attrs[j][i]);
536 }
537 }
538 }
539}
+ Here is the call graph for this function:

◆ addChildrenWithOptionalAttributes() [1/2]

void addChildrenWithOptionalAttributes ( XMLDocument doc,
XMLNode n,
const string &  names,
const string &  name,
const vector< T > &  values,
const string &  attrName,
const vector< string > &  attrs 
)
static

Definition at line 542 of file xmlutils.cpp.

544 {
545 addChildrenWithOptionalAttributes(doc, n, names, name, values, vector<string>{attrName},
546 vector<vector<string>>{attrs});
547}
static void addChildrenWithOptionalAttributes(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values, const string &attrName, const vector< string > &attrs)
Definition: xmlutils.cpp:542
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addChildrenWithOptionalAttributes() [2/2]

void addChildrenWithOptionalAttributes ( XMLDocument doc,
XMLNode n,
const string &  names,
const string &  name,
const vector< T > &  values,
const vector< string > &  attrNames,
const vector< vector< string > > &  attrs 
)
static

Definition at line 550 of file xmlutils.cpp.

552 {
553 QL_REQUIRE(attrNames.size() == attrs.size(),
554 "attrNames size (" << attrNames.size() << ") must match attrs size (" << attrs.size() << ")");
555 for (auto const& attr : attrs)
556 QL_REQUIRE(attr.empty() == attrs.front().empty(), "all attributes must be empty or non-empty at the same time");
557 if (attrs.empty() || attrs.front().empty())
558 XMLUtils::addChildren(doc, n, names, name, values);
559 else
560 XMLUtils::addChildrenWithAttributes(doc, n, names, name, values, attrNames, attrs);
561}
static void addChildren(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values)
Definition: xmlutils.cpp:502
+ Here is the call graph for this function:

◆ addChildren() [2/2]

void addChildren ( XMLDocument doc,
XMLNode n,
const string &  names,
const string &  name,
const string &  firstName,
const string &  secondName,
const map< string, string > &  values 
)
static

Definition at line 264 of file xmlutils.cpp.

265 {
266 QL_REQUIRE(parent, "XML Node is null (Adding " << names << ")");
267 XMLNode* node = addChild(doc, parent, names);
268 map<string, string>::const_iterator it;
269 for (it = values.begin(); it != values.end(); ++it) {
270 XMLNode* n = addChild(doc, node, name);
271 QL_REQUIRE(n, "XML AllocNode failure (" << name << ")");
272 addChild(doc, n, firstName, it->first);
273 addChild(doc, n, secondName, it->second);
274 }
275}
+ Here is the call graph for this function:

◆ getChildValue()

string getChildValue ( XMLNode node,
const string &  name,
bool  mandatory = false,
const string &  defaultValue = string() 
)
static

Definition at line 277 of file xmlutils.cpp.

277 {
278 QL_REQUIRE(node, "XMLNode is NULL (was looking for child " << name << ")");
279 xml_node<>* child = node->first_node(name.c_str());
280 if (mandatory) {
281 QL_REQUIRE(child, "Error: No XML Child Node " << name << " found.");
282 }
283 return child ? getNodeValue(child) : defaultValue;
284}
static string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildValueAsDouble()

Real getChildValueAsDouble ( XMLNode node,
const string &  name,
bool  mandatory = false,
double  defaultValue = 0.0 
)
static

Definition at line 286 of file xmlutils.cpp.

286 {
287 string s = getChildValue(node, name, mandatory);
288 return s == "" ? defaultValue : parseReal(s);
289}
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildValueAsInt()

int getChildValueAsInt ( XMLNode node,
const string &  name,
bool  mandatory = false,
int  defaultValue = 0 
)
static

Definition at line 291 of file xmlutils.cpp.

291 {
292 string s = getChildValue(node, name, mandatory);
293 return s == "" ? defaultValue : parseInteger(s);
294}
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildValueAsBool()

bool getChildValueAsBool ( XMLNode node,
const string &  name,
bool  mandatory = false,
bool  defaultValue = true 
)
static

Definition at line 296 of file xmlutils.cpp.

296 {
297 string s = getChildValue(node, name, mandatory);
298 return s == "" ? defaultValue : parseBool(s);
299}
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildValueAsPeriod()

Period getChildValueAsPeriod ( XMLNode node,
const string &  name,
bool  mandatory = false,
const QuantLib::Period &  defaultValue = 0 * QuantLib::Days 
)
static

Definition at line 301 of file xmlutils.cpp.

301 {
302 string s = getChildValue(node, name, mandatory);
303 return s == "" ? defaultValue : parsePeriod(s);
304}
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Definition: parsers.cpp:171
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildrenValues() [1/2]

vector< string > getChildrenValues ( XMLNode node,
const string &  names,
const string &  name,
bool  mandatory = false 
)
static

Definition at line 306 of file xmlutils.cpp.

306 {
307 vector<string> vec;
308 xml_node<>* node = parent->first_node(names.c_str());
309 if (mandatory) {
310 QL_REQUIRE(node, "Error: No XML Node " << names << " found.");
311 }
312 if (node) {
313 for (xml_node<>* child = node->first_node(name.c_str()); child; child = child->next_sibling(name.c_str()))
314 vec.push_back(getNodeValue(child));
315 }
316 return vec;
317}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildrenValuesWithAttributes() [1/4]

vector< string > getChildrenValuesWithAttributes ( XMLNode node,
const string &  names,
const string &  name,
const string &  attrName,
vector< string > &  attrs,
bool  mandatory = false 
)
static

Definition at line 563 of file xmlutils.cpp.

565 {
566 return getChildrenValuesWithAttributes<string>(
567 parent, names, name, attrName, attrs, [](const string& x) { return x; }, mandatory);
568}
+ Here is the caller graph for this function:

◆ getChildrenValuesWithAttributes() [2/4]

vector< string > getChildrenValuesWithAttributes ( XMLNode node,
const string &  names,
const string &  name,
const vector< string > &  attrNames,
const vector< std::reference_wrapper< vector< string > > > &  attrs,
bool  mandatory = false 
)
static

Definition at line 579 of file xmlutils.cpp.

582 {
583 return getChildrenValuesWithAttributes<string>(
584 parent, names, name, attrNames, attrs, [](const string& x) { return x; }, mandatory);
585}

◆ getChildrenValuesWithAttributes() [3/4]

vector< T > getChildrenValuesWithAttributes ( XMLNode node,
const string &  names,
const string &  name,
const string &  attrName,
vector< string > &  attrs,
const std::function< T(string)>  parser,
bool  mandatory = false 
)
static

Definition at line 571 of file xmlutils.cpp.

573 {
574 std::vector<std::reference_wrapper<vector<string>>> attrs_v;
575 attrs_v.push_back(attrs);
576 return getChildrenValuesWithAttributes(parent, names, name, vector<string>{attrName}, attrs_v, parser, mandatory);
577}
static vector< string > getChildrenValuesWithAttributes(XMLNode *node, const string &names, const string &name, const string &attrName, vector< string > &attrs, bool mandatory=false)
Definition: xmlutils.cpp:563
+ Here is the call graph for this function:

◆ getChildrenValuesWithAttributes() [4/4]

vector< T > getChildrenValuesWithAttributes ( XMLNode node,
const string &  names,
const string &  name,
const vector< string > &  attrNames,
const vector< std::reference_wrapper< vector< string > > > &  attrs,
const std::function< T(string)>  parser,
bool  mandatory = false 
)
static

Definition at line 588 of file xmlutils.cpp.

591 {
592 QL_REQUIRE(parser, "XMLUtils::getChildrenValuesWithAttributes(): parser is null");
593 QL_REQUIRE(attrNames.size() == attrs.size(),
594 "attrNames size (" << attrNames.size() << ") must match attrs size (" << attrs.size() << ")");
595 vector<T> vec;
596 // if 'names' is not given, use the parent node directly
597 rapidxml::xml_node<>* node = names.empty() ? parent : parent->first_node(names.c_str());
598 if (mandatory) {
599 QL_REQUIRE(node, "Error: No XML Node " << names << " found.");
600 }
601 if (node) {
602 for (rapidxml::xml_node<>* child = node->first_node(name.c_str()); child;
603 child = child->next_sibling(name.c_str())) {
604
605 std::string vstr = getNodeValue(child);
606 vec.push_back(parser(vstr));
607
608 for (Size i = 0; i < attrNames.size(); ++i) {
609 xml_attribute<>* attr = child->first_attribute(attrNames[i].c_str());
610 if (attr && attr->value())
611 ((vector<string>&)attrs[i]).push_back(attr->value());
612 else
613 ((vector<string>&)attrs[i]).push_back("");
614 }
615 }
616 }
617 return vec;
618}
+ Here is the call graph for this function:

◆ getChildrenValuesAsDoubles()

vector< Real > getChildrenValuesAsDoubles ( XMLNode node,
const string &  names,
const string &  name,
bool  mandatory = false 
)
static

Definition at line 319 of file xmlutils.cpp.

320 {
321 vector<string> vecS = getChildrenValues(node, names, name, mandatory);
322 vector<Real> vecD(vecS.size());
323 std::transform(vecS.begin(), vecS.end(), vecD.begin(), parseReal);
324 return vecD;
325}
static vector< string > getChildrenValues(XMLNode *node, const string &names, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:306
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildrenValuesAsDoublesCompact()

vector< Real > getChildrenValuesAsDoublesCompact ( XMLNode node,
const string &  name,
bool  mandatory = false 
)
static

Definition at line 327 of file xmlutils.cpp.

327 {
328 string s = getChildValue(node, name, mandatory);
329 return parseListOfValues(s, std::function<Real(string)>(&parseReal));
330}
std::vector< string > parseListOfValues(string s, const char escape, const char delim, const char quote)
Definition: parsers.cpp:639
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildrenValuesAsPeriods()

vector< Period > getChildrenValuesAsPeriods ( XMLNode node,
const string &  name,
bool  mandatory = false 
)
static

Definition at line 337 of file xmlutils.cpp.

337 {
338 string s = getChildValue(node, name, mandatory);
339 return parseListOfValues(s, std::function<Period(string)>(&parsePeriod));
340}
+ Here is the call graph for this function:

◆ getChildrenValuesAsStrings()

vector< string > getChildrenValuesAsStrings ( XMLNode node,
const string &  name,
bool  mandatory = false 
)
static

Definition at line 342 of file xmlutils.cpp.

342 {
343 string s = getChildValue(node, name, mandatory);
344 return parseListOfValues(s);
345}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildrenValues() [2/2]

map< string, string > getChildrenValues ( XMLNode node,
const string &  names,
const string &  name,
const string &  firstName,
const string &  secondName,
bool  mandatory = false 
)
static

Definition at line 347 of file xmlutils.cpp.

348 {
349 map<string, string> res;
350 xml_node<>* node = parent->first_node(names.c_str());
351 if (mandatory) {
352 QL_REQUIRE(node, "Error: No XML Node " << names << " found.");
353 }
354 if (node) {
355 for (xml_node<>* child = node->first_node(name.c_str()); child; child = child->next_sibling(name.c_str())) {
356 string first = getChildValue(child, firstName, mandatory);
357 string second = getChildValue(child, secondName, mandatory);
358 // res[first] = second;
359 res.insert(pair<string, string>(first, second));
360 }
361 }
362 return res;
363}
+ Here is the call graph for this function:

◆ getChildrenAttributesAndValues()

map< string, string > getChildrenAttributesAndValues ( XMLNode parent,
const string &  names,
const string &  attributeName,
bool  mandatory = false 
)
static

Definition at line 365 of file xmlutils.cpp.

366 {
367 map<string, string> res;
368 for (XMLNode* child = getChildNode(parent, names.c_str()); child;
369 child = XMLUtils::getNextSibling(child, names.c_str())) {
370 string first = getAttribute(child, attributeName);
371 string second = getNodeValue(child);
372 if (first.empty())
373 continue;
374 auto it = res.find(first);
375 if (it != res.end())
376 WLOG("XMLUtils::getChildrenAttributesAndValues: Duplicate entry " << first <<
377 " in node " << names << ". Overwritting with value " << second << ".");
378 res.insert(pair<string, string>(first, second));
379 }
380 if (mandatory) {
381 QL_REQUIRE(!res.empty(), "Error: No XML Node " << names << " found.");
382 }
383 return res;
384}
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
Definition: xmlutils.cpp:484
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildNode()

XMLNode * getChildNode ( XMLNode n,
const string &  name = "" 
)
static

Definition at line 387 of file xmlutils.cpp.

387 {
388 QL_REQUIRE(n, "XMLUtils::getChildNode(" << name << "): XML Node is NULL");
389 return n->first_node(name == "" ? nullptr : name.c_str());
390}
+ Here is the caller graph for this function:

◆ locateNode()

XMLNode * locateNode ( XMLNode n,
const string &  name = "" 
)
static

Definition at line 393 of file xmlutils.cpp.

393 {
394 QL_REQUIRE(n, "XMLUtils::locateNode(" << name << "): XML Node is NULL");
395 if (n->name() == name)
396 return n;
397 else {
398 const char* p = name.empty() ? nullptr : name.c_str();
399 XMLNode* node = n->first_node(p);
400 QL_REQUIRE(node, "XML node with name " << name << " not found");
401 return node;
402 }
403}
+ Here is the caller graph for this function:

◆ appendNode()

void appendNode ( XMLNode parent,
XMLNode child 
)
static

Definition at line 406 of file xmlutils.cpp.

406 {
407 QL_REQUIRE(parent, "XMLUtils::appendNode() parent is NULL");
408 QL_REQUIRE(child, "XMLUtils::appendNode() child is NULL");
409 parent->append_node(child);
410}
+ Here is the caller graph for this function:

◆ addAttribute()

void addAttribute ( XMLDocument doc,
XMLNode node,
const string &  attrName,
const string &  attrValue 
)
static

Definition at line 412 of file xmlutils.cpp.

412 {
413 QL_REQUIRE(node, "XMLUtils::appendAttribute(" << attrName << "," << attrName << ") node is NULL");
414 char* name = doc.allocString(attrName.c_str());
415 char* value = doc.allocString(attrValue.c_str());
416 node->append_attribute(doc.doc()->allocate_attribute(name, value));
417}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAttribute()

string getAttribute ( XMLNode node,
const string &  attrName 
)
static

Definition at line 419 of file xmlutils.cpp.

419 {
420 QL_REQUIRE(node, "XMLUtils::getAttribute(" << attrName << ") node is NULL");
421 xml_attribute<>* attr = node->first_attribute(attrName.c_str());
422 if (attr && attr->value())
423 return string(attr->value());
424 else
425 return "";
426}
+ Here is the caller graph for this function:

◆ getChildrenNodes()

vector< XMLNode * > getChildrenNodes ( XMLNode node,
const string &  name 
)
static

Returns all the children with a given name.

Definition at line 428 of file xmlutils.cpp.

428 {
429 QL_REQUIRE(node, "XMLUtils::getChildrenNodes(" << name << ") node is NULL");
430 vector<XMLNode*> res;
431 const char* p = name.empty() ? nullptr : name.c_str();
432 for (xml_node<>* c = node->first_node(p); c; c = c->next_sibling(p))
433 res.push_back(c);
434 return res;
435}
+ Here is the caller graph for this function:

◆ getChildrenNodesWithAttributes() [1/2]

vector< XMLNode * > getChildrenNodesWithAttributes ( XMLNode node,
const string &  names,
const string &  name,
const string &  attrName,
vector< string > &  attrs,
bool  mandatory = false 
)
static

Definition at line 437 of file xmlutils.cpp.

439 {
440 std::vector<std::reference_wrapper<vector<string>>> attrs_v;
441 attrs_v.push_back(attrs);
442 return getChildrenNodesWithAttributes(parent, names, name, {attrName}, attrs_v, mandatory);
443}
static vector< XMLNode * > getChildrenNodesWithAttributes(XMLNode *node, const string &names, const string &name, const string &attrName, vector< string > &attrs, bool mandatory=false)
Definition: xmlutils.cpp:437
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildrenNodesWithAttributes() [2/2]

vector< XMLNode * > getChildrenNodesWithAttributes ( XMLNode node,
const string &  names,
const string &  name,
const vector< string > &  attrNames,
const vector< std::reference_wrapper< vector< string > > > &  attrs,
bool  mandatory = false 
)
static

Definition at line 445 of file xmlutils.cpp.

448 {
449 QL_REQUIRE(attrNames.size() == attrs.size(),
450 "attrNames size (" << attrNames.size() << ") must match attrs size (" << attrs.size() << ")");
451 vector<XMLNode*> vec;
452 // if names is empty, use the parent as the anchor node
453 rapidxml::xml_node<>* node = names.empty() ? parent : parent->first_node(names.c_str());
454 if (mandatory) {
455 QL_REQUIRE(node, "Error: No XML Node " << names << " found.");
456 }
457 if (node) {
458 for (rapidxml::xml_node<>* child = node->first_node(name.c_str()); child;
459 child = child->next_sibling(name.c_str())) {
460 vec.push_back(child);
461 for (Size i = 0; i < attrNames.size(); ++i) {
462 xml_attribute<>* attr = child->first_attribute(attrNames[i].c_str());
463 if (attr && attr->value())
464 ((vector<string>&)attrs[i]).push_back(attr->value());
465 else
466 ((vector<string>&)attrs[i]).push_back("");
467 }
468 }
469 }
470 return vec;
471}

◆ getNodeName()

string getNodeName ( XMLNode n)
static

Get and set a node's name.

Definition at line 473 of file xmlutils.cpp.

473 {
474 QL_REQUIRE(node, "XMLUtils::getNodeName(): XML Node is NULL");
475 return node->name();
476}
+ Here is the caller graph for this function:

◆ setNodeName()

void setNodeName ( XMLDocument doc,
XMLNode node,
const string &  name 
)
static

Definition at line 478 of file xmlutils.cpp.

478 {
479 QL_REQUIRE(node, "XMLUtils::setNodeName(" << name << "): XML Node is NULL");
480 char* nodeName = doc.allocString(name);
481 node->name(nodeName);
482}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNextSibling()

XMLNode * getNextSibling ( XMLNode node,
const string &  name = "" 
)
static

Get a node's next sibling node.

Definition at line 484 of file xmlutils.cpp.

484 {
485 QL_REQUIRE(node, "XMLUtils::getNextSibling(" << name << "): XML Node is NULL");
486 return node->next_sibling(name == "" ? nullptr : name.c_str());
487}
+ Here is the caller graph for this function:

◆ getNodeValue()

string getNodeValue ( XMLNode node)
static

Get a node's value.

Definition at line 489 of file xmlutils.cpp.

489 {
490 QL_REQUIRE(node, "XMLUtils::getNodeValue(): XML Node is NULL");
491 // handle CDATA nodes
492 XMLNode* n = node->first_node();
493 if (n && n->type() == node_cdata)
494 return n->value();
495 // all other cases
496 return node->value();
497}
+ Here is the caller graph for this function:

◆ getNodeValueAsDoublesCompact()

vector< Real > getNodeValueAsDoublesCompact ( XMLNode node)
static

Get a node's compact values as vector of doubles.

Definition at line 332 of file xmlutils.cpp.

332 {
333 string s = getNodeValue(node);
334 return parseListOfValues(s, std::function<Real(string)>(&parseReal));
335}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString()

string toString ( XMLNode node)
static

Write a node out as a string.

Definition at line 714 of file xmlutils.cpp.

714 {
715 string xml_as_string;
716 rapidxml::print(std::back_inserter(xml_as_string), *node);
717 return xml_as_string;
718}
+ Here is the caller graph for this function:

◆ convertToString() [1/2]

string convertToString ( const Real  value)
static

Definition at line 620 of file xmlutils.cpp.

620 {
621 // We want to write out a double that conforms to xs:double, this means no
622 // scientific notation, so we check for really small numbers here and explicitly set
623 // to 16 decimal places
624 string result;
625 if (std::abs(value) < 1.0e-6) {
626 std::ostringstream obj1;
627 obj1.precision(16);
628 obj1 << std::fixed << value;
629 result = obj1.str();
630 } else {
631 // And here we just use boost::lexical_cast which is better
632 // at precision than std::to_string()
633 result = boost::lexical_cast<std::string>(value);
634 }
635 return result;
636}
+ Here is the caller graph for this function:

◆ convertToString() [2/2]

string convertToString ( const T &  value)
static

Definition at line 638 of file xmlutils.cpp.

638{ return boost::lexical_cast<std::string>(value); }