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 @ 2024-06-30 17:25  alvinlyb  阅读(1)  评论(0编辑  收藏  举报