Archive 17/01/2023.

[SOLVED] XML File Read and Write

zerokol

Hello, I’m trying to load a content from a XML file (It is my game score database), update some content then save it in archive again.

All is almost right.

First of all I set these two global variables:

XMLFile@ baseXMLFile; XMLElement baseXMLElement;

then initialize it:

baseXMLFile = cache.GetResource("XMLFile", "base.xml"); baseXMLElement = baseXMLFile.root;

I use the XMLElement methods to modify the content, all right, but only not SetValue(const String&)

when a try to save:

File file; file.Open("base.xml", FILE_READWRITE); baseXMLElement.file.Save(file);

My initial file was (base.xml)

[code]<?xml version="1.0"?>

Charles Xavier Thor [/code]

After save:

[code]<?xml version="1.0"?>

Charles Xavier Thor aj alves Thor [/code]

What is going wrong, why can not I change the XMLElement value?
Is there a best approach to open/update/save files?

cadaver

This is a legitimate bug in XMLElement. It’s always appending a new value instead of rewriting the old, if one already exists. Should be fixed in the near future.

EDIT: fix is in the master branch.

zerokol

Works like a glove! Thanks!