TwitterUser::TwitterUser(const wxXmlNode& node) { ParseXmlNode(node); if (!wxFile::Exists(GetProfileImageFilename())) { GetProfileImage(); } }
template <class StringType, class CharType> Bool ParseXmlNode(xml_node<CharType>* pNode, CXmlElement<StringType>* pElement) { if (pNode && pElement) { if (pNode->type() == rapidxml::node_element && pNode->name_size()) { //标签数据 pElement->SetTag(StringType(pNode->name(), pNode->name_size())); //属性数据 if (pNode->value_size()) pElement->SetValue(StringType(pNode->value(), pNode->value_size())); //读取属性 pElement->Attributes.reserve(rapidxml::count_children<CharType>(pNode)); xml_attribute<CharType>* pNodeAttr = pNode->first_attribute(); while (pNodeAttr) { if (pNodeAttr->name_size()) { pElement->AddAttribute(CXmlAttribute<StringType>( StringType(pNodeAttr->name(), pNodeAttr->name_size()), StringType(pNodeAttr->value(), pNodeAttr->value_size()))); } pNodeAttr = pNodeAttr->next_attribute(); } //子节点预开辟空间 pElement->Children.reserve(rapidxml::count_children<CharType>(pNode)); xml_node<CharType>* pChildNode = pNode->first_node(); while (pChildNode) { if (pChildNode->type() == rapidxml::node_element && pChildNode->name_size()) { CXmlElement<StringType>* pChildElement = pElement->AddChildren(StringType(pChildNode->name(), pChildNode->name_size())); if (!ParseXmlNode(pChildNode, pChildElement)) return false; } pChildNode = pChildNode->next_sibling(); } } return true; } return false; }