• UE XML解析


    1. bool UHermesFunctionLibrary::isFileExist(const FString& Path)
    2. {
    3. return FPlatformFileManager::Get().GetPlatformFile().FileExists(*Path);
    4. }
    5. FString UHermesFunctionLibrary::ReadXmlFile(const FString& Path, bool& isSuccess)
    6. {
    7. if(!isFileExist(Path)){
    8. isSuccess = false;
    9. return FString("");
    10. }
    11. TSharedPtr<FXmlFile> XmlFile = MakeShareable(new FXmlFile(Path));
    12. if(!XmlFile->IsValid()){
    13. isSuccess = false;
    14. return FString("");
    15. }
    16. FString Content;
    17. FXmlNode* RootNode = XmlFile->GetRootNode();
    18. for(FXmlNode* ChildNode : RootNode->GetChildrenNodes())
    19. {
    20. FString strValue = ChildNode->GetAttribute("category");
    21. for(FXmlNode* SubChildNode : ChildNode->GetChildrenNodes())
    22. {
    23. FString subStrValue = SubChildNode->GetAttribute("lang");
    24. Content = SubChildNode->GetContent();
    25. if(!isSuccess) isSuccess = true;
    26. }
    27. }
    28. return Content;
    29. }

    1. FString UHermesFunctionLibrary::ReadXmlFile(const FString& Path, const FString& Tag, bool& isSuccess)
    2. {
    3. TSharedPtr<FXmlFile> XmlFile = MakeShareable(new FXmlFile(Path));
    4. if(!XmlFile->IsValid() || !isFileExist(Path)){
    5. isSuccess = false;
    6. return FString("");
    7. }
    8. FXmlNode* RootNode = XmlFile->GetRootNode();
    9. for(FXmlNode* ChildNode : RootNode->GetChildrenNodes())
    10. {
    11. if(ChildNode->GetTag() == Tag) return ChildNode->GetContent();
    12. }
    13. return FString("");
    14. }

     

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


    1. FString UHermesFunctionLibrary::ReadXmlFile(const FString& Path, const FString& Tag, bool& isSuccess)//暂时做两层用于XML读取,以后升级
    2. {
    3. TSharedPtr<FXmlFile> XmlFile = MakeShareable(new FXmlFile(Path));
    4. if(!XmlFile->IsValid() || !isFileExist(Path)){
    5. isSuccess = false;
    6. return FString("");
    7. }
    8. FXmlNode* RootNode = XmlFile->GetRootNode();
    9. for(FXmlNode* ChildNode : RootNode->GetChildrenNodes())
    10. {
    11. if (ChildNode->GetAttribute("category") == "COOKING") return ChildNode->GetContent();
    12. //if(ChildNode->GetTag() == Tag) return ChildNode->GetContent();
    13. }
    14. return FString("");
    15. }

    PrivateDependencyModuleNames.AddRange(new string[] { "XmlParser" });加载.cs里面


    1. FXmlNode* UHermesFunctionLibrary::FindXmlNode(FXmlNode* RootNode, const FString& Contribution) {
    2. if (RootNode == nullptr) return nullptr;
    3. for (FXmlNode* ChildNode : RootNode->GetChildrenNodes())
    4. {
    5. for (const FXmlAttribute& xmlAttribute : ChildNode->GetAttributes()) {
    6. if (xmlAttribute.GetValue() == Contribution) {
    7. return ChildNode;
    8. }
    9. }
    10. }
    11. for (FXmlNode* ChildNode : RootNode->GetChildrenNodes()) {
    12. FXmlNode* foundNode = FindXmlNode(ChildNode, Contribution);
    13. if (foundNode != nullptr) return foundNode;
    14. }
    15. return nullptr;
    16. }
    17. FString UHermesFunctionLibrary::ReadXmlFileByContribution(const FString& Path, const FString& Contribution, bool& isSuccess) {
    18. TSharedPtr<FXmlFile> XmlFile = MakeShareable(new FXmlFile(Path));
    19. if (!XmlFile->IsValid() || !isFileExist(Path)) {
    20. isSuccess = false;
    21. return FString("");
    22. }
    23. FXmlNode* RootNode = XmlFile->GetRootNode();
    24. FXmlNode* foundNode = FindXmlNode(RootNode, Contribution);
    25. if(foundNode == nullptr) return FString("");
    26. return foundNode->GetContent();
    27. }

    递归xml解析

  • 相关阅读:
    Vue 3 中用组合式函数和 Shared Worker 实现后台分片上传(带哈希计算)
    李沐67_自注意力——自学笔记
    Redis单线程和多线程
    2014年3月13日 Go生态洞察:并发模式与管道取消技术
    Android系统升级A/B分区OTA升级应用层调用UpdateEngine代码
    二战华为成功上岸,准备了小半年,要个27k应该也算不上很高吧~
    【解包裹】基于GPSA和AIA实现相位提取附matlab代码
    C语言中自定义类型讲解
    2023 年最新Java 毕业设计选题题目参考,500道 Java 毕业设计题目,值得收藏
    译文伪原创的全文翻译软件
  • 原文地址:https://blog.csdn.net/qqQQqsadfj/article/details/132742393