build.cs 添加 XmlParser 模块
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "Json","XmlParser" });
引擎支持读写操作,写入操作可以通过 SetContent 和 AppendChildNode进行扩展。代码中的一些方法为私有,可见引擎建议进行读取操作。
FXmlFile
LoadFile
Clear
IsValid
GetRootNode
FXmlNode
GetNextNode
GetChildrenNodes
GetFirstChildNode
FindChildNode
GetTag
GetContent
SetContent
GetAttributes
GetAttribute
AppendChildNode
FString XmlPath = FPaths::ProjectDir() + TEXT("DataDrive/Movies.xml");
XmlPath = FPaths::ConvertRelativePathToFull(XmlPath);
if (FPaths::FileExists(XmlPath))
FXmlFile* XmlFile = new FXmlFile(XmlPath);
// 获取根节点
FXmlNode* RootNode = XmlFile->GetRootNode();
// 获取属性值
FString MovieName = RootNode->GetAttribute(TEXT("Name"));
// 获取子节点
FXmlNode* CategoryNode = RootNode->FindChildNode(TEXT("Category"));
// 获取子节点的值
FString MovieCategory = CategoryNode->GetContent();
FString MovieDirector = RootNode->FindChildNode(TEXT("Director"))->GetContent();
FString MovieTime = RootNode->FindChildNode(TEXT("Time"))->GetContent();
UE_LOG(LogTemp, Warning, TEXT("%s\t%s\t%s\t%s\t"), *MovieName, *MovieCategory, *MovieDirector, *MovieTime);
使用 tinyxml第三方库
tinyxml
原博客地址 https://www.cnblogs.com/shiroe/p/14765224.html