XmlParser 为引擎自带模块
<?xml version="1.0" encoding="UTF-8"?> <Movie Name="悬崖之上"> <Category>剧情/悬疑/动作</Category> <Director>张艺谋</Director> <Time>2021-04-30</Time> </Movie>
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "Json","XmlParser" });
引擎支持读写操作,写入操作可以通过 SetContent 和 AppendChildNode进行扩展。代码中的一些方法为私有,可见引擎建议进行读取操作。
FXmlFile
FXmlNode
简单实现
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
待续