Esempio n. 1
0
	void AppendDocumentCopy(pugi::xml_node& target, pugi::xml_document& doc) {
		auto doc_children = doc.children();

		for(auto doc_child : doc_children) {
			target.append_copy(doc_child);
		}
	}
Esempio n. 2
0
void mergeNodes(pugi::xml_node toNode, pugi::xml_node& fromNode)
{
  // Base case = both nodes are text nodes
  pugi::xml_text fromNodeText = fromNode.text();
  pugi::xml_text toNodeText = toNode.text();
  if (fromNodeText && toNodeText) {
    SBLog::info() << "Overwriting template value of \"" << toNode.name() << "\" from \"" << toNodeText.get() << "\" to \"" << fromNodeText.get() << "\"." << std::endl;
    toNodeText.set(fromNodeText.get());
    return;
  }

  // Calculate number of children in toNode
  unsigned maxDistance = std::distance(toNode.begin(), toNode.end());

  // Merge children
  for (pugi::xml_node fromNodeChild = fromNode.first_child(); fromNodeChild; fromNodeChild = fromNodeChild.next_sibling()) {
    // Find appropriate merge point
    pugi::xml_node toNodeChild = findSimilarNode(fromNodeChild, toNode, maxDistance);
    if (toNodeChild) {
      mergeNodes(toNodeChild, fromNodeChild);
    } else {
      toNode.append_copy(fromNodeChild);
    }
  }

  // Erase fromNode
  removeNode(fromNode);
}
int VR_DataAccessorNaviCN::getAddressMappingResult(pugi::xml_node &firstItem, pugi::xml_node &itemsNode, std::string &mappingType)
{
    int count = 0;
    VR_MappingTypeCN firstResultType = VR_MappingTypeCN::EMPTY;
    pugi::xml_node itemNodeTemplate = itemsNode.first_child();
    for (pugi::xml_node itemNode = firstItem; !itemNode.empty(); itemNode = itemNode.next_sibling()) {
        pugi::xml_node itemAddressNode = itemNode.first_child();
        std::string zone = itemAddressNode.child(VR_MSG_NAVI_ZONE).text().as_string();
        std::string city = itemAddressNode.child(VR_MSG_NAVI_CITY).text().as_string();
        std::string district = itemAddressNode.child(VR_MSG_NAVI_DISTRICT).text().as_string();
        std::string street = itemAddressNode.child(VR_MSG_NAVI_STREET).text().as_string();
        std::string streetBody = itemAddressNode.child(VR_MSG_NAVI_STREET_BODY).text().as_string();
        std::string houseNumber = itemAddressNode.child(VR_MSG_NAVI_HOUSE_NUMBER).text().as_string();

        VR_MappingTypeCN currentType = VR_MappingTypeCN::EMPTY;
        if (!zone.empty()) {
            currentType = VR_MappingTypeCN::TILL_STATE;
            if (!street.empty()) {
                currentType = VR_MappingTypeCN::TILL_STREET;
                if (!houseNumber.empty()) {
                    currentType = VR_MappingTypeCN::FULL;
                }
            }
            else {
                if (!district.empty()) {
                    currentType = VR_MappingTypeCN::TILL_DISTRICT;
                }
                else {
                    if (!city.empty()) {
                        currentType = VR_MappingTypeCN::TILL_CITY;
                    }
                }
            }
        }

        if (VR_MappingTypeCN::EMPTY == firstResultType) {
            if (VR_MappingTypeCN::EMPTY == currentType) {
                return count;
            }
            firstResultType = currentType;
        }

        if (firstResultType != currentType) {
            continue;
        }
        pugi::xml_node addressNode = itemsNode.append_copy(itemNodeTemplate).child(VR_MSG_NAVI_ADDRESS_ID);
        switch (firstResultType) {
        case VR_MappingTypeCN::FULL:
            addressNode.child(VR_MSG_NAVI_HOUSE_NUMBER).text().set(houseNumber.c_str());
        // need add stret info to addressNode
        case VR_MappingTypeCN::TILL_STREET:
            addressNode.child(VR_MSG_NAVI_STREET).text().set(street.c_str());
            addressNode.child(VR_MSG_NAVI_STREET_BODY).text().set(streetBody.c_str());
        // need add district info to addressNode
        case VR_MappingTypeCN::TILL_DISTRICT:
            addressNode.child(VR_MSG_NAVI_DISTRICT).text().set(district.c_str());
        // need add city info to addressNode
        case VR_MappingTypeCN::TILL_CITY:
            addressNode.child(VR_MSG_NAVI_CITY).text().set(city.c_str());
        // need add state info to addressNode
        case VR_MappingTypeCN::TILL_STATE:
            addressNode.child(VR_MSG_NAVI_ZONE).text().set(zone.c_str());
            break;
        default:
            break;
        }
        ++count;
    }

    // remove the itemNodeTemplate node
    itemsNode.remove_child(itemsNode.first_child());

    // get mappingType
    switch (firstResultType) {
    case VR_MappingTypeCN::FULL:
        mappingType = VR_MSG_RESPONSE_ADDRESS_MAPPING_TYPE_FULL;
        break;
    case VR_MappingTypeCN::TILL_STREET:
        mappingType = VR_MSG_RESPONSE_ADDRESS_MAPPING_TYPE_TILL_STREET;
        break;
    case VR_MappingTypeCN::TILL_DISTRICT:
        mappingType = VR_MSG_RESPONSE_ADDRESS_MAPPING_TYPE_TILL_DISTRICT;
        break;
    case VR_MappingTypeCN::TILL_CITY:
        mappingType = VR_MSG_RESPONSE_ADDRESS_MAPPING_TYPE_TILL_CITY;
        break;
    case VR_MappingTypeCN::TILL_STATE:
        mappingType = VR_MSG_RESPONSE_ADDRESS_MAPPING_TYPE_TILL_STATE;
        break;
    default:
        break;
    }

    return count;
}