UE XML解析

bool UHermesFunctionLibrary::isFileExist(const FString& Path)
{
	return FPlatformFileManager::Get().GetPlatformFile().FileExists(*Path);
}

FString UHermesFunctionLibrary::ReadXmlFile(const FString& Path, bool& isSuccess)
{
	if(!isFileExist(Path)){
		isSuccess = false;
		return FString("");
	}
	TSharedPtr XmlFile = MakeShareable(new FXmlFile(Path));
	if(!XmlFile->IsValid()){
		isSuccess = false;
		return FString("");
	}
	FString Content;
	FXmlNode* RootNode = XmlFile->GetRootNode();
	for(FXmlNode* ChildNode : RootNode->GetChildrenNodes())
	{
		FString strValue = ChildNode->GetAttribute("category");
		for(FXmlNode* SubChildNode : ChildNode->GetChildrenNodes())
		{
			FString subStrValue = SubChildNode->GetAttribute("lang");
			Content = SubChildNode->GetContent();
			if(!isSuccess)	isSuccess = true;
		}
	}
	return Content;
}

UE XML解析_第1张图片

UE XML解析_第2张图片

FString UHermesFunctionLibrary::ReadXmlFile(const FString& Path, const FString& Tag, bool& isSuccess)
{
	TSharedPtr XmlFile = MakeShareable(new FXmlFile(Path));
	if(!XmlFile->IsValid() || !isFileExist(Path)){
		isSuccess = false;
		return FString("");
	}
	FXmlNode* RootNode = XmlFile->GetRootNode();
	for(FXmlNode* ChildNode : RootNode->GetChildrenNodes())
	{
		if(ChildNode->GetTag() == Tag)	return ChildNode->GetContent();
	}

	return FString("");
}

 UE XML解析_第3张图片

UE XML解析_第4张图片

这里如果要GetTag()则得改成 == title

UE XML解析_第5张图片

你可能感兴趣的:(xml)