#pragma warning (disable: 4996) 
#pragma warning (disable: 4819) 

#include <cstdio>

#include <io.h>
#include <iostream>
#include "tinyxml.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "atlstr.h"
using namespace std;
int amain() {
	string path = "C:\\Users\\user\\Desktop\\精雕.xml";
	TiXmlDocument* pDoc = new TiXmlDocument();
	pDoc->LoadFile(path.c_str());
	pDoc->Print();
	//获取根节点
	TiXmlElement* pRoot = pDoc->RootElement();
	printf("%s\n", pRoot->Value());//标签名

	printf("%s\n", pRoot->FirstChild()->ToText()->Value());
	string t_Item_info = pRoot->FirstChild()->ToText()->Value();//
	printf("t_Item_info=%s\n", t_Item_info.c_str());
	//获取Item标签
	TiXmlElement* itemElement = pRoot->FirstChildElement("ITEM");//物料类型
	printf("item标签名称%s\n", itemElement->Value());//标签名
	TiXmlElement *nextItemElement = itemElement;
	//循环遍历根节点下的兄弟节点
	char type[50] = "";
	char sessionId[50] = "";
	char transNowTime[50] = "";
	char transStatus[50] = "";
	char itemId[50] = "";
	char itemRev[50] = "";
	char itemName[50] = "";
	char itemRelease[50] = "";
	char temp[50] = "";
	while (nextItemElement) {
		const char* attribute_value = nextItemElement->Attribute("type");
		strcpy(type, attribute_value);  // 将 str 复制给 copy
		printf("type=%s\n", type);

		TiXmlElement* pChild = nextItemElement->FirstChildElement("SESSIONID");
		attribute_value = pChild->Attribute("val");
		strcpy(sessionId, attribute_value);  // 将 str 复制给 copy
		printf("sessionId=%s\n", sessionId);

		pChild = nextItemElement->FirstChildElement("TRANSNOWTIME");
		if (pChild != NULL) {
			attribute_value = pChild->Attribute("val");
			strcpy(transNowTime, attribute_value);  // 将 str 复制给 copy;
			printf("transNowTime=%s\n", transNowTime);
		}
		pChild = nextItemElement->FirstChildElement("TRANSSTATUS");
		if (pChild != NULL) {
			attribute_value = pChild->Attribute("val");
			strcpy(transStatus, attribute_value);  // 将 str 复制给 copy;
			printf("transStatus=%s\n", transStatus);;
		}


		pChild = nextItemElement->FirstChildElement("ITEMID");
		if (pChild != NULL) {
			attribute_value = pChild->Attribute("val");
			strcpy(itemId, attribute_value);  // 将 str 复制给 copy;
			printf("itemId=%s\n", itemId);
		}


		pChild = nextItemElement->FirstChildElement("ITEMREV");
		if (pChild != NULL) {
			attribute_value = pChild->Attribute("val");
			strcpy(itemRev, attribute_value);  // 将 str 复制给 copy;
			printf("itemRev=%s\n", itemRev);
		}

		pChild = nextItemElement->FirstChildElement("ITEMNAME");
		if (pChild != NULL) {
			attribute_value = pChild->Attribute("val");
			strcpy(itemName, attribute_value);  // 将 str 复制给 copy;
			printf("itemName=%s\n", itemName);
		}
		pChild = nextItemElement->FirstChildElement("ITEMRELEASE");
		if (pChild != NULL) {
			attribute_value = pChild->Attribute("val");
			strcpy(itemRelease, attribute_value);  // 将 str 复制给 copy;
			printf("itemRelease=%s\n", itemRelease);
		}
		//itemRelease = attribute_value;
		nextItemElement = nextItemElement->NextSiblingElement();
	}


	//转换时间
	time_t currentTime;
	struct tm *timeInfo;
	char timeString[80];

	// 获取当前时间
	time(&currentTime);

	// 将时间转换为本地时间
	timeInfo = localtime(&currentTime);

	// 将时间按照指定格式转换为字符串
	strftime(timeString, sizeof(timeString), transNowTime, timeInfo);

	// 打印转换后的时间字符串
	printf("当前时间：%s\n", timeString);
	delete pDoc;//应该是必要的
	system("pause");
	return 0;
}