1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
| void RouteNode::route2xml(Route route) { xml_document<> doc; xml_node<> *rot = doc.allocate_node(rapidxml::node_pi, doc.allocate_string("xml version='1.0' encoding='utf-8'")); doc.append_node(rot);
xml_node<> *node = doc.allocate_node(node_element, "route", "imformation"); node->append_attribute(doc.allocate_attribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")); node->append_attribute(doc.allocate_attribute("xmlns", "http://www.cirm.org/RTZ/1/1")); node->append_attribute(doc.allocate_attribute("version", "1.1")); node->append_attribute(doc.allocate_attribute("xmlns:stm", "http://stmvalidation.eu/STM/1/0/0")); node->append_attribute(doc.allocate_attribute("xsi:schemaLocation", "http://stmvalidation.eu/STM/1/0/0 stm_extensions.xsd")); doc.append_node(node); xml_node<> *routeInfo = doc.allocate_node(node_element, "routeInfo", NULL); routeInfo->append_attribute(doc.allocate_attribute("routeName", "Example_routes")); node->append_node(routeInfo);
xml_node<> *waypoints = doc.allocate_node(node_element, "waypoints", "imformation"); node->append_node(waypoints);
for (int i = 0; i < route.m_waypoints.size(); i++) { std::string id = std::to_string(route.m_waypoints[i].m_id); char *idc = doc.allocate_string(id.c_str());
std::string radius = std::to_string(route.m_waypoints[i].m_radius); char *radiusc = doc.allocate_string(radius.c_str()); std::string latitude = std::to_string(route.m_waypoints[i].m_latitude); char *latitudec = doc.allocate_string(latitude.c_str()); std::string longitude = std::to_string(route.m_waypoints[i].m_longitude); char *longitudec = doc.allocate_string(longitude.c_str());
xml_node<> *waypoint = doc.allocate_node(node_element, "waypoint", "imformation"); waypoint->append_attribute(doc.allocate_attribute("id", idc)); waypoint->append_attribute(doc.allocate_attribute("radius", radiusc)); waypoints->append_node(waypoint);
xml_node<> *position = doc.allocate_node(node_element, "position", NULL); position->append_attribute(doc.allocate_attribute("lat", latitudec)); position->append_attribute(doc.allocate_attribute("lon", longitudec));
xml_node<> *leg = doc.allocate_node(node_element, "leg", NULL); leg->append_attribute(doc.allocate_attribute("starboardXTD", "0.026998")); leg->append_attribute(doc.allocate_attribute("portsideXTD", "0.026998")); leg->append_attribute(doc.allocate_attribute("geometryType", "Loxodrome")); waypoint->append_node(position); waypoint->append_node(leg); } xml_node<> *schedules = doc.allocate_node(node_element, "schedules", "imformation"); node->append_node(schedules); xml_node<> *schedule = doc.allocate_node(node_element, "schedule", "imformation"); schedule->append_attribute(doc.allocate_attribute("id", "1")); schedules->append_node(schedule); xml_node<> *manual = doc.allocate_node(node_element, "manual", "imformation"); schedule->append_node(manual); for (int i = 0; i < route.m_waypoints.size(); i++) { if (i != route.m_waypoints.size() - 1) { std::string id = std::to_string(route.m_waypoints[i].m_id); char *idc = doc.allocate_string(id.c_str());
std::string speed = std::to_string(route.m_waypoints[i].m_speed); char *speedc = doc.allocate_string(speed.c_str());
xml_node<> *scheduleElement = doc.allocate_node(node_element, "scheduleElement", NULL); scheduleElement->append_attribute(doc.allocate_attribute("waypointId", idc)); scheduleElement->append_attribute(doc.allocate_attribute("speed", speedc)); manual->append_node(scheduleElement); } else { std::string id = std::to_string(route.m_waypoints[i].m_id); char *idc = doc.allocate_string(id.c_str());
std::string speed = std::to_string(route.m_waypoints[i].m_speed); char *speedc = doc.allocate_string(speed.c_str());
xml_node<> *scheduleElement = doc.allocate_node(node_element, "scheduleElement", NULL); scheduleElement->append_attribute(doc.allocate_attribute("waypointId", idc)); scheduleElement->append_attribute(doc.allocate_attribute("eta", "2019-06-17T12:28:24+02:00")); scheduleElement->append_attribute(doc.allocate_attribute("speed", speedc)); manual->append_node(scheduleElement); } } xml_node<> *calculated = doc.allocate_node(node_element, "calculated", "imformation"); schedule->append_node(calculated); for (int i = 0; i < route.m_waypoints.size(); i++) { if (i == 0) { std::string id = std::to_string(route.m_waypoints[i].m_id); char *idc = doc.allocate_string(id.c_str());
std::string speed = std::to_string(route.m_waypoints[i].m_speed); char *speedc = doc.allocate_string(speed.c_str());
xml_node<> *scheduleElement = doc.allocate_node(node_element, "scheduleElement", NULL); scheduleElement->append_attribute(doc.allocate_attribute("waypointId", idc)); scheduleElement->append_attribute(doc.allocate_attribute("etd", "2019-06-17T12:22:31+02:00")); scheduleElement->append_attribute(doc.allocate_attribute("speed", speedc)); calculated->append_node(scheduleElement); } else if (i == route.m_waypoints.size() - 1) { std::string id = std::to_string(route.m_waypoints[i].m_id); char *idc = doc.allocate_string(id.c_str());
std::string speed = std::to_string(route.m_waypoints[i].m_speed); char *speedc = doc.allocate_string(speed.c_str());
xml_node<> *scheduleElement = doc.allocate_node(node_element, "scheduleElement", NULL); scheduleElement->append_attribute(doc.allocate_attribute("waypointId", idc)); scheduleElement->append_attribute(doc.allocate_attribute("eta", "2019-06-17T12:28:24+02:00")); scheduleElement->append_attribute(doc.allocate_attribute("speed", speedc)); calculated->append_node(scheduleElement); } else { std::string id = std::to_string(route.m_waypoints[i].m_id); char *idc = doc.allocate_string(id.c_str());
std::string speed = std::to_string(route.m_waypoints[i].m_speed); char *speedc = doc.allocate_string(speed.c_str());
xml_node<> *scheduleElement = doc.allocate_node(node_element, "scheduleElement", NULL); scheduleElement->append_attribute(doc.allocate_attribute("waypointId", idc)); scheduleElement->append_attribute(doc.allocate_attribute("speed", speedc)); calculated->append_node(scheduleElement); } } std::string text; rapidxml::print(std::back_inserter(text), doc, 0);
std::cout << text << std::endl;
std::ofstream out("config11.xml"); out << doc; }
|