| 40 | } |
| 41 | |
| 42 | void processNode(const YAML::Node & node, Poco::XML::Element & parent_xml_node) |
| 43 | { |
| 44 | auto * xml_document = parent_xml_node.ownerDocument(); |
| 45 | switch (node.Type()) |
| 46 | { |
| 47 | case YAML::NodeType::Scalar: |
| 48 | { |
| 49 | std::string value = node.as<std::string>(); |
| 50 | Poco::AutoPtr<Poco::XML::Text> xml_value = xml_document->createTextNode(value); |
| 51 | parent_xml_node.appendChild(xml_value); |
| 52 | break; |
| 53 | } |
| 54 | |
| 55 | /// For sequences we repeat the parent xml node. For example, |
| 56 | /// seq: |
| 57 | /// - val1 |
| 58 | /// - val2 |
| 59 | /// is converted into the following xml: |
| 60 | /// <seq>val1</seq> |
| 61 | /// <seq>val2</seq> |
| 62 | /// |
| 63 | /// A sequence of mappings is converted in the same way: |
| 64 | /// seq: |
| 65 | /// - k1: val1 |
| 66 | /// k2: val2 |
| 67 | /// - k3: val3 |
| 68 | /// is converted into the following xml: |
| 69 | /// <seq><k1>val1</k1><k2>val2</k2></seq> |
| 70 | /// <seq><k3>val3</k3></seq> |
| 71 | case YAML::NodeType::Sequence: |
| 72 | { |
| 73 | size_t i = 0; |
| 74 | for (auto it = node.begin(); it != node.end(); ++it, ++i) |
| 75 | { |
| 76 | const auto & child_node = *it; |
| 77 | |
| 78 | bool need_clone_parent_xml_node = (i > 0); |
| 79 | |
| 80 | if (need_clone_parent_xml_node) |
| 81 | { |
| 82 | /// Create a new parent node with same tag for each child node |
| 83 | processNode(child_node, *cloneXMLNode(parent_xml_node)); |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | /// Map, so don't recreate the parent node but add directly |
| 88 | processNode(child_node, parent_xml_node); |
| 89 | } |
| 90 | } |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | case YAML::NodeType::Map: |
| 95 | { |
| 96 | for (const auto & key_value_pair : node) |
| 97 | { |
| 98 | const auto & key_node = key_value_pair.first; |
| 99 | const auto & value_node = key_value_pair.second; |
no test coverage detected