poco

Poco::log

Poco::json

Poco::XML

void LPocoXml::OpenFile(const string &path)
    {
    	 InputSource src(path);
    	 try
    	 {
    		 Poco::XML::DOMParser parset;
    		 Poco::AutoPtr<Document> pDoc = parset.parse(&src);

    		 int pCount = atoi((GetNodeAttr("PersonS", "personCount",pDoc)).c_str());
    		 for (int i = 1; i <= pCount; i++) {
    			 struct Person tempPerson;
    			 char name[MAX_PATH];
    			 char age[MAX_PATH];
    			 char address[MAX_PATH];
    			 sprintf_s(name, sizeof(name), "PersonS/Person[@id='%d']/elem[@eName='name']", i);
    			 sprintf_s(age, sizeof(age), "PersonS/Person[@id='%d']/elem[@eName='age']", i);
    			 sprintf_s(address, sizeof(address), "PersonS/Person[@id='%d']/elem[@eName='address']", i);

    			 strcpy(tempPerson.name, (GetNodeAttr(name, "value", pDoc)).c_str());
    			 tempPerson.age = atoi(GetNodeAttr(age, "value", pDoc).c_str());
    			 strcpy(tempPerson.address, (GetNodeAttr(address, "value", pDoc)).c_str());

    			 qDebug() << tempPerson.name<<endl;
    			 qDebug() << tempPerson.age<<endl;
    			 qDebug() << tempPerson.address<<endl;
    		 }

    		 /*
    		 NodeIterator it(pDoc, NodeFilter::SHOW_ALL);
    		 Node* pNode = it.nextNode();		//指向第0个节点
    		 while (pNode)
    		 {
    			 NamedNodeMap* nodeMap = pNode->attributes();	//return the node attribut
    			 //遍历nodeMap中所有属性
    			 if (nodeMap)
    			 {
    				 for (int i = 0; i < nodeMap->length(); i++) {
    					 Node* attr = nodeMap->item(i);
    					 std::cout << attr->nodeName() << std::endl;
    					 std::cout << attr->nodeValue() << std::endl;
    				 }
    			 }
    			 std::cout << pNode->nodeName() << std::endl;
    			 std::cout << pNode->nodeValue() << std::endl;

    			 pNode = it.nextNode();
    		 }
    		 */
    	 }
    	 catch (Poco::Exception& e)
    	 {
    		 std::cerr << e.displayText() << std::endl;
    	 }
    }
posted @   alvinlyb  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示