SmartPtrCXmlElement CConfigProvider::findXmlElement(
	const std::deque<std::string>& keyPathCollection,
	const SmartPtrCXmlElement& rootXml) const {
	CAF_CM_FUNCNAME("findXmlElement");

	SmartPtrCXmlElement xmlRc;

	CAF_CM_ENTER {
		CAF_CM_VALIDATE_STL(keyPathCollection);
		CAF_CM_VALIDATE_SMARTPTR(rootXml);

		xmlRc = rootXml;
		for (std::deque<std::string>::const_iterator keyPathIter = keyPathCollection.begin();
			keyPathIter != keyPathCollection.end();
			keyPathIter++) {
			const std::string keyPath = *keyPathIter;

			if (keyPathIter == keyPathCollection.begin()) {
				if (xmlRc->getName().compare(keyPath) != 0) {
					CAF_CM_EXCEPTIONEX_VA2(NoSuchElementException, ERROR_NOT_FOUND,
						"Root element does not match - %s != %s", keyPath.c_str(), xmlRc->getName().c_str());
				}
			} else {
				xmlRc = xmlRc->findRequiredChild(keyPath);
			}
		}
	}
	CAF_CM_EXIT;

	return xmlRc;
}
std::deque<std::pair<std::string, std::string> > CConfigProvider::createXmlFilePropertyCollection(
	const std::string& filePath) const {
	CAF_CM_FUNCNAME_VALIDATE("createXmlFilePropertyCollection");

	std::deque<std::pair<std::string, std::string> > propertyCollection;

	CAF_CM_ENTER {
		CAF_CM_VALIDATE_STRING(filePath);

		const SmartPtrCXmlElement rootXml = CXmlUtils::parseFile(filePath, std::string());

		const std::string keyPath = rootXml->getName();
		createXmlPropertyCollection(keyPath, rootXml, propertyCollection);
	}
	CAF_CM_EXIT;

	return propertyCollection;
}
void CConfigProvider::createXmlPropertyCollection(
	const std::string& keyPath,
	const SmartPtrCXmlElement& thisXml,
	std::deque<std::pair<std::string, std::string> >& propertyCollection) const {
	CAF_CM_FUNCNAME_VALIDATE("createXmlPropertyCollection");

	CAF_CM_ENTER {
		CAF_CM_VALIDATE_STRING(keyPath);
		CAF_CM_VALIDATE_SMARTPTR(thisXml);
		// propertyCollection is optional

		const CXmlElement::SmartPtrCAttributeCollection attributeCollection = thisXml->getAllAttributes();
		if (! attributeCollection.IsNull() && ! attributeCollection->empty()) {
			for (TConstIterator<CXmlElement::CAttributeCollection> attributeXmlIter(*attributeCollection);
				attributeXmlIter; attributeXmlIter++) {
				const std::string attributeName = attributeXmlIter->first;
				const std::string attributeValue = attributeXmlIter->second;

				const std::string newKeyPath = keyPath + _keyPathDelimStr + attributeName;
				propertyCollection.push_back(std::make_pair(newKeyPath, attributeValue));
			}
		}

		const CXmlElement::SmartPtrCElementCollection childrenXml = thisXml->getAllChildren();
		if (! childrenXml.IsNull() && ! childrenXml->empty()) {
			for (TConstIterator<CXmlElement::CElementCollection > childrenXmlIter(*childrenXml);
				childrenXmlIter; childrenXmlIter++) {
				const SmartPtrCXmlElement childXml = childrenXmlIter->second;
				const std::string newKeyPath = keyPath + _keyPathDelimStr + childXml->getName();

				const std::string value = childXml->getValue();
				if (! value.empty()) {
					propertyCollection.push_back(std::make_pair(newKeyPath, value));
				}

				createXmlPropertyCollection(newKeyPath, childXml, propertyCollection);
			}
		}
	}
	CAF_CM_EXIT;
}