| 190 | } |
| 191 | |
| 192 | void WriteAssessmentFile(std::string const fileName, pugi::xml_document const & doc, |
| 193 | std::vector<DecodedPath> const & paths) |
| 194 | { |
| 195 | ankerl::unordered_dense::map<uint32_t, pugi::xml_node> xmlSegments; |
| 196 | for (auto const & xpathNode : doc.select_nodes("//reportSegments")) |
| 197 | { |
| 198 | auto const xmlSegment = xpathNode.node(); |
| 199 | xmlSegments[xmlSegment.child("ReportSegmentID").text().as_uint()] = xmlSegment; |
| 200 | } |
| 201 | |
| 202 | pugi::xml_document result; |
| 203 | auto segments = result.append_child("Segments"); |
| 204 | auto const dict = doc.select_node(".//Dictionary").node(); |
| 205 | char const xmlns[] = "xmlns"; |
| 206 | |
| 207 | // Copy namespaces from <Dictionary> to <Segments> |
| 208 | for (auto const & attr : dict.attributes()) |
| 209 | { |
| 210 | if (strncmp(xmlns, attr.name(), sizeof(xmlns) - 1) != 0) |
| 211 | continue; |
| 212 | |
| 213 | // Don't copy default namespace. |
| 214 | if (strncmp(xmlns, attr.name(), sizeof(xmlns)) == 0) |
| 215 | continue; |
| 216 | |
| 217 | segments.append_copy(attr); |
| 218 | } |
| 219 | |
| 220 | for (auto const & p : paths) |
| 221 | { |
| 222 | auto segment = segments.append_child("Segment"); |
| 223 | { |
| 224 | auto const xmlSegment = xmlSegments[p.m_segmentId.Get()]; |
| 225 | segment.append_copy(xmlSegment); |
| 226 | } |
| 227 | if (!p.m_path.empty()) |
| 228 | { |
| 229 | auto node = segment.append_child("Route"); |
| 230 | openlr::PathToXML(p.m_path, node); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | result.save_file(fileName.data(), " " /* indent */); |
| 235 | } |
| 236 | } // namespace |
| 237 | |
| 238 | int main(int argc, char * argv[]) |