bool CTaoBaoTask::checkNodesByIdAndText( std::string idValue, std::string textValue, TiXmlElement *root, std::string &outString )
{
//	printLog("==checkNodesByIdAndText== idValue = %s\n",idValue.c_str());
//	printLog("==checkNodesByIdAndText== textValue = %s\n",textValue.c_str());
	TiXmlElement *nextElement = root;
	std::string idattr;
	std::string textattr;
	std::wstring wText;
	//循环遍历根节点下的兄弟节点
	while(nextElement)

	{
		const char *c_idattr = nextElement->Attribute("resource-id") ;
		if (!c_idattr)
		{
			goto ERROR__;
		}
		const char *c_textattr = nextElement->Attribute("text");
		if (!c_textattr)
		{
			goto ERROR__;
		}
		idattr=c_idattr ;
		textattr=c_textattr;
		
		UTF8_to_Unicode(textattr.c_str(),textattr.length(),wText);
		Unicode_to_ANSI(wText.c_str(),wText.length(),textattr);
	//	TiXmlAttribute * attr = nextElement->FirstAttribute();

		if (idattr == "com.taobao.taobao:id/title" )
		{

			printLog("id  :%s---%s\n",idattr.c_str(),textattr.c_str());
			if (textattr.find(textValue) != -1)
			{
				printLog("FOUND   ======= %s\n",textattr.c_str());
				m_dataTool->m_targetTitle = (textattr);
				return true;
			}
		}
ERROR__:
		//查找下一个兄弟节点的指针
		TiXmlElement * firtChildNode = nextElement->FirstChildElement();
		if (firtChildNode)
		{
			if (checkNodesByIdAndText(idValue,textValue,firtChildNode,outString))
			{
				return true;
			}
		}
		nextElement = nextElement->NextSiblingElement();

	}
	return false;
}
Exemple #2
0
int LuaWin32Shell::SetIEMainPage(lua_State* luaState)
{
	const char* lpUrl = luaL_checkstring(luaState, 2);
	if (lpUrl)
	{
		CRegKey reg;
		if (reg.Open(HKEY_CURRENT_USER, L"Software\\Microsoft\\Internet Explorer\\Main") == ERROR_SUCCESS)
		{
			std::wstring strUrl;
			UTF8_to_Unicode(lpUrl, ::strlen(lpUrl), strUrl);
			if (reg.SetStringValue(L"Start Page", strUrl.c_str()) == ERROR_SUCCESS)
			{
				lua_pushboolean(luaState, 1);
				return 1;
			}
		}
	}

	lua_pushboolean(luaState, 0);
	return 1;
}
std::string CTaoBaoTask::getTextById( std::string idValue,TiXmlElement *root )
{
	std::wstring wRet;
	int outLen=0;
	std::string s_bounds;
	TiXmlString s1;
	int pos = 0;//name(//*[@resource-id=' '])
	s_bounds = ("//*[@resource-id='");
	s_bounds +=	idValue;
	s_bounds += ("']/@text");
	std::wstring tmpWstr;
	ANSI_to_Unicode(s_bounds.c_str(),s_bounds.length(),tmpWstr);
	Unicode_to_UTF8(tmpWstr.c_str(),tmpWstr.length(),s_bounds);
	s1 = TinyXPath::S_xpath_string(root,s_bounds.c_str());
	s_bounds = s1.c_str();
	UTF8_to_Unicode(s_bounds.c_str(),s_bounds.length(),wRet);
	Unicode_to_ANSI(wRet.c_str(),wRet.length(),s_bounds);

	printLog("==getTextById== idValue = %s\n",idValue.c_str());
	printLog("==getTextById== Result  = %s\n",s_bounds.c_str());

	return s_bounds;

}