原文链接:http://blog.csdn.net/u011047958/article/details/78861469
解析文件的引用:
FFastXml存在于Runtime/XmlParser/Public/FastXml.h头文件中
API Document中关于FFastXml的用法说的还是很清楚的,因此,本篇之简要说明一下基本使用规则:
基于此,继承IFastXmlCallback接口后,你需要实现以下5个接口函数,它们会在读取XML时被回调:
virtualboolProcessAttribute(constTCHAR*AttributeName,constAttributeValue)override;//Xml属性处理
virtualboolProcessClose(constElement)override;//Xml Element结束时处理
virtualboolProcessComment(constElement)override;//Xml注释处理
virtualboolProcessElement(constElementName,128);min-height:11pt;">ElementData,int32XmlFileLineNumber)override;//子节点处理
virtualboolProcessXmlDeclaration(constXmlFileLineNumber)override;//声明处理
核心函数:
bool ParseXmlFile(class IFastXmlCallback,TCHAR* XmlFilePath,TCHAR* XmlFileContents,FFeedbackContext*,bool,FText&,int32&);
情况下,另一需要非空。
xmlFileContents非空,适用于项目工程内部Xml字符串的读取。
FFastXml解析的一种封装与使用:
//XmlHandleComponent.h
#pragmaonce
#include"CoreMinimal.h"
"FastXml.h"
"XmlHandleComponent.generated.h"
classUActorComponent;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FProcessAttributeDelegate,FString,AttributeName,AttributeValue);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FProcessCloseDelegate,Element);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FProcessCommentDelegate,Element);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FProcessElementDelegate,ElementName,ElementData,175);min-height:11pt;">int32,XmlFileLineNumber);
UCLASS(Meta = (BlueprintSpawnableComponent))
classUXmlHandleComponent:publicUActorComponent,publicIFastXmlCallback
{
GENERATED_BODY()
public:
UXmlHandleComponent();
~XmlHandleComponent();
virtualboolProcessAttribute(constAttributeValue)override;
virtualboolProcessClose(constElement)override;
virtualboolProcessComment(constElement)override;
virtualboolProcessElement(constXmlFileLineNumber)override;
virtualboolProcessXmlDeclaration(constXmlFileLineNumber)override;
UFUNCTION(BlueprintCallable,Category="XmlParser")
boolParseXmlFileFromPath(constFString&Path,boolbShowSlowTaskDialog,128);min-height:11pt;">bShowCancelButton);
UFUNCTION(BlueprintCallable,Category ="XmlParser")
boolParseXmlFileFromContent(FString&Content,128);min-height:11pt;">bShowCancelButton);
public:
UPROPERTY(BlueprintAssignable,21);min-height:11pt;">"XmlParser")
FProcessAttributeDelegateProcessAttributeDelegate;
UPROPERTY(BlueprintAssignable,175);min-height:11pt;">FProcessCloseDelegateProcessCloseDelegate;
UPROPERTY(BlueprintAssignable,175);min-height:11pt;">FProcessCommentDelegateProcessCommentDelegate;
UPROPERTY(BlueprintAssignable,175);min-height:11pt;">FProcessElementDelegateProcessElementDelegate;
UPROPERTY(BlueprintAssignable,175);min-height:11pt;">FProcessXmlDeclarationDelegateProcessXmlDeclarationDelegate;
};
//XmlHandleComponent.cpp
"UXmlHandleComponent.h"
"Components/ActorComponent.h"
"Paths.h"
XmlHandleComponent::XmlHandleComponent()
{
}
XmlHandleComponent::~XmlHandleComponent()
{
}
boolXmlHandleComponent::ProcessAttribute(constAttributeValue)
{
ProcessAttributeDelegate.broadcast(FString(AttributeName),128);min-height:11pt;">AttributeValue));
returntrue;
}
boolXmlHandleComponent::ProcessClose(constElement)
{
ProcessCloseDelegate.broadcast(Element));
returntrue;
}
boolXmlHandleComponent::ProcessComment(constElement)
{
{
ProcessElementDelegate.broadcast(ElementName),128);min-height:11pt;">ElementData),XmlFileLineNumber);
returntrue;
}
boolXmlHandleComponent::ProcessXmlDeclaration(constXmlFileLineNumber)
{
ProcessXmlDeclarationDelegate.broadcast(XmlHandleComponent::ParseXmlFileFromPath(constboolbShowSlowTaskDialog=false,128);min-height:11pt;">bShowCancelButton=false)
{
booltempBool=FFastXml::ParseXmlFile(this,*NULL,nullptr,128);min-height:11pt;">bShowCancelButton,mOutErrorMessage,OutErrorLineNumber);
returntempBool;
}
boolXmlHandleComponent::ParseXmlFileFromContent(bShowSlowTaskDialog=false,128);min-height:11pt;">bShowCancelButton=false)
{
booltempBool =Content.GetChararray().GetData(),OutErrorLineNumber);
returntempBool;
}