Is there an XML Writer in unreal?

Hi there,

Is there an XML Document writer in Unreal Engine?

Thanks!

EDIT:

Seems like it is not possible for now, I added a feature request for it: https://answers.unrealengine.com/questions/453762/feature-request-xml-writer-exporter.html

If you haven’t found it yet there are a few classes you can look at:

FXmlFile* xmlFile = new FXmlFile();
if (xmlFile == nullptr)
    return;

FXmlNode* xmlRoot = xmlFile->GetRootNode();
if (xmlRoot == nullptr)
    return;

FXmlAttribute* xmlAttribute = new FXmlAttribute(TEXT("Name"), TEXT("MyGame"));
if (xmlAttribute == nullptr)
    return;

xmlRoot->SetContent(TEXT("Game"));

xmlFile->Save(filename);
xmlFile->Clear();

delete xmlAttribute;
delete xmlFile;
1 Like

Thanks for the help! However as I looked over the source code one should not create a new FXmlFile without a path. You can, but then the RootNode is set to nulltpr:

/** Constructs the file without a path */
FXmlFile() : RootNode(nullptr), bFileLoaded(false) {}

Hence, the part with the GetRootNode() will return a nullptr :(.

Can it be that the API is only made for reading the XML files?

EDIT:

It can be done by creating the xml file from string (see https://answers.unrealengine.com/questions/435638/is-there-an-xml-writer-in-unreal.html):

const FString FileTemplate = "<?xml version=\"1.0\" encoding=\"UTF - 8\"?>\n<root>\n</root>";
     FXmlFile * File = new FXmlFile(FileTemplate, EConstructMethod::ConstructFromBuffer);
1 Like

What id the point of the FXmlAttribute here? You create it but then can never do anything with it. The return type of GetAttributes on a node is const and there is no add attribute. This confuses me because a node has a TArray of attributes but only ever can hold one. Is there any way to add an attribute to a node?

Or you can checkout this plugin.

Two years later, same Question! Did you by any chance find a solution to this? (how to add an attribute to a node)