虚幻4引擎 读取XML文件
1.导入XmlParser模块
![在这里插入图片描述](https://img-blog.csdnimg.cn/e5ced3a5fa0c4c39809573c55031c458.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0V6X2NvZGVy,size_16,color_FFFFFF,t_70)
2.1读取方式一
从根节点读
//读XML文档
TSharedPtr<FXmlFile> xmlRead(new FXmlFile(TEXT("D:\\UEclass\\UECPP\\XML\\Data.xml"))); //TEXT里内容为文件目录
//读取根
FXmlNode * RootNode = xmlRead->GetRootNode();
//读取当前节点下的所有子节点
TArray<FXmlNode*> AllChidren = RootNode->GetChildrenNodes();
if (AllChidren.Num() > 0)
{
FString Content = AllChidren[0]->GetContent();
GEngine->AddOnScreenDebugMessage(-1, 2, FColor::Red, Content);
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/14408249463d4e7099ca5ba5e4c73dbf.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0V6X2NvZGVy,size_16,color_FFFFFF,t_70)
2.2读取方式二
通过固定标签读取
//通过标签查找
FXmlNode * FNode = RootNode->FindChildNode(TEXT("from"));
if (FNode)
{
GEngine->AddOnScreenDebugMessage(-1, 2, FColor::Green, *FNode->GetContent());
}
效果
![在这里插入图片描述](https://img-blog.csdnimg.cn/f45394ca0a164bd6bb4ef7b230599d6b.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0V6X2NvZGVy,size_16,color_FFFFFF,t_70)