How to use FFastXml for XML parsing?

Hi all, I’m learning how to parse an XML file using the new fancy FFastXml class and first of all I cannot find any examples at all about this, making it hard to understand, so far I managed to get things up and running only with a few flaws so far, like I still cannot call FFastXml::ParseXmlFile() because the compiler says that ParseXmlFile is not defined in the FFastXml class, so any examples on this would be gold for me.

And as far as the implementation, this is my line of code for the parsing on my .cpp file:

FFastXml::ParseXmlFile(this, “D:\Projects\UnrealProjects\UnrealShooter\Source\Shared\Xml\UnrealShooterData.xml”, GWarn, false, false, &OutErrorMessage, &ErrorLineNumber);

Since there is a huge lack of documentation on this I decided to switch to JSON data storage and parsing. I would still be interested in understanding how this works though.

Did you include XMLParser in your dependencies in the Build.cs file & “FastXml.h”?

You also need to create a class which inherits IFastXmlCallback. Once you start parsing it will call the interface methods. I’m not sure if my list is complete but the following is what I used in one of my projects.

Then from within your XMLParser class you can call it like this and the callbacks will begin firing so you can then do what you want with the information. It doesn’t parse into an object that is searchable later, you have to store the information yourself.

FString XML = <your XML>;
bool success = FFastXml::ParseXmlFile((IFastXmlCallback*)this, TEXT(""), XML.GetCharArray().GetData(), nullptr, false, false, outError, outErrorNum);

class XMLParser : public IFastXmlCallback

	bool ProcessXmlDeclaration(const TCHAR* ElementData, int32 XmlFileLineNumber);
	bool ProcessElement(const TCHAR* ElementName, const TCHAR* ElementData, int32 XmlFileLineNumber);
	bool ProcessAttribute(const TCHAR* AttributeName, const TCHAR* AttributeValue);
	bool ProcessClose(const TCHAR* Element);
	bool ProcessComment(const TCHAR* Comment);


Yes I did add the module in the Build.cs file and I also included the FastXml.h, the class I was testing with inherited from IFastXmlCallback and implemented those methods as you said. My problem was that no matter what I did I couldn’t call FFastXml::ParseXmlFile(). So at this point in time I don’t need it anymore but it was a shame I couldn’t use the xml parser. By the way the JSON parsing is pretty straighforward, I would totally recommend it.

Are you looking for examples of using Fast XML specifically? I have some code examples if using FXmlFile to read XML if you’re interested.

I am interested in seeing how you made FXmlFile work, for me I cant even include FXmlFile the header is no where to be found. Im sure Im doing something wrong so I would appreciate it If I can see your example code

Honestly, I don’t remember what project I was even working on five years ago and I haven’t had to use and XML Parser since, but if you have downloaded the Engine source I would recommend taking a look at SPlistEditor.cpp, specifically the function named ParseXmlTree. You should find a good example of how to parse XML with the engine from there.