43 lines
1.3 KiB
C++

#pragma once
// tinyxml2头文件
#include "XNCore_global.h"
#include "XNString.h"
#include <tinyxml2.h>
namespace XNSim {
using XN_XMLDocument = tinyxml2::XMLDocument;
using XN_XMLElement = tinyxml2::XMLElement;
FORCEINLINE XN_INT32 LoadXmlFile(const XN_STRING &filePath,
XN_XMLDocument &doc) {
if (doc.LoadFile(filePath.c_str()) != tinyxml2::XML_SUCCESS) {
return -1;
}
return 0;
}
FORCEINLINE XN_XMLElement *GetRootElement(XN_XMLDocument &doc) {
return doc.RootElement();
}
FORCEINLINE XN_XMLElement *GetFirstChildElement(XN_XMLElement *element,
const XN_STRING &name) {
return element->FirstChildElement(name.c_str());
}
FORCEINLINE XN_STRING GetFirstChildElementText(XN_XMLElement *element,
const XN_STRING &name) {
return XN_STRING(GetFirstChildElement(element, name)->GetText());
}
FORCEINLINE XN_XMLElement *GetNextSiblingElement(XN_XMLElement *element,
const XN_STRING &name) {
return element->NextSiblingElement(name.c_str());
}
FORCEINLINE XN_STRING GetAttribute(XN_XMLElement *element,
const XN_STRING &name) {
return XN_STRING(element->Attribute(name.c_str()));
}
} // namespace XNSim