Hello,
I created, in c++, functions based on the XML libraries from Epic.
When a file is read, the characters on the blueprint debug show as having encoding problems.
I included in the XML the header :
<?xml version="1.0" encoding="utf-8" ?>
but it doesn’t work.
Do I need to add something?
bool UDatabaseManager::readXML(FString fileName)
{
if (currentFile != nullptr) {
//saveXML();
}
FString path = FPaths::GameDir() + FString("Content/A_RTS/UnitInfo/") + fileName + ".xml";
filePath = path;
currentFile = new FXmlFile(*path);
if (currentFile->IsValid()) {
fileLoaded = true;
return true;
}
fileLoaded = false;
return false;
}
bool UDatabaseManager::saveXML()
{
if (fileLoaded) {
return currentFile->Save(*filePath);
}
return false;
}
bool UDatabaseManager::addChildNode(FString parent, FString newTag, FString newValue)
{
if (fileLoaded) {
FXmlNode* root = currentFile->GetRootNode();
root->FindChildNode(parent)->AppendChildNode(newTag, newValue);
return true;
}
return false;
}
bool UDatabaseManager::removeChildNode(FString parent, FString tagToRemove)
{
if (fileLoaded) {
FXmlNode* root = currentFile->GetRootNode();
FXmlNode* parentNode = root->FindChildNode(parent);
TArray<FXmlNode*> parentsChildren = parentNode->GetChildrenNodes();
FXmlNode* toRemove = parentNode->FindChildNode(tagToRemove);
if (toRemove != nullptr) {
parentsChildren.Remove(toRemove);
if (parentsChildren.Find(toRemove) == INDEX_NONE) {
return true;
}
else {
return false;
}
}
return true;
}
return false;
}
TArray<FString> UDatabaseManager::listObjectsName()
{
TArray<FString> toReturn;
if (fileLoaded) {
FXmlNode* root = currentFile->GetRootNode();
TArray<FXmlNode*> children = root->GetChildrenNodes();
for (FXmlNode* node : children) {
toReturn.Add(node->GetTag());
}
return toReturn;
}
return toReturn;
}
TArray<UObjectAttribute*> UDatabaseManager::listObjectChildrens(FString name)
{
TArray<UObjectAttribute*> toReturn;
if (fileLoaded) {
FXmlNode* target = currentFile->GetRootNode()->FindChildNode(name);
if (target != nullptr) {
TArray <FXmlNode*> characteristics = target->GetChildrenNodes();
for (FXmlNode* node : characteristics) {
UObjectAttribute * newAttb = NewObject<UObjectAttribute>();
if (node->GetChildrenNodes().Num() > 0) { // has children
for (FXmlNode* child : node->GetChildrenNodes()) {
UObjectAttribute * temp = NewObject<UObjectAttribute>();
temp->attbName = child->GetTag();
if (child->GetChildrenNodes().Num() > 0) {
temp->childs = listObjectChildrensWithRoot(child->GetTag(), node);
}
else {
temp->attbValue = child->GetContent();
}
newAttb->childs.Add(temp);
}
}
newAttb->attbName = node->GetTag();
newAttb->attbValue = node->GetContent();
toReturn.Add(newAttb);
}
return toReturn;
}
}
return toReturn;
}
TArray<UObjectAttribute*> UDatabaseManager::getObjectDetails(FString name)
{
TArray<UObjectAttribute*> toReturn;
if (fileLoaded) {
FXmlNode* target = currentFile->GetRootNode()->FindChildNode(name);
if (target != nullptr) {
TArray <FXmlNode*> characteristics = target->GetChildrenNodes();
if (characteristics.Num() != 0) {
for (FXmlNode* node : characteristics) {
UObjectAttribute * newAttb = NewObject<UObjectAttribute>();
if (node->GetChildrenNodes().Num() > 0) { // has children
for (FXmlNode* child : node->GetChildrenNodes()) {
UObjectAttribute * temp = NewObject<UObjectAttribute>();
temp->attbName = child->GetTag();
if (child->GetChildrenNodes().Num() > 0) {
temp->childs = listObjectChildrensWithRoot(child->GetTag(), node);
}
else {
temp->attbValue = child->GetContent();
}
newAttb->childs.Add(temp);
}
}
newAttb->attbName = node->GetTag();
newAttb->attbValue = node->GetContent();
toReturn.Add(newAttb);
}
}
else {
UObjectAttribute * temp = NewObject<UObjectAttribute>();
temp->attbName = target->GetTag();
temp->attbValue = target->GetContent();
toReturn.Add(temp);
}
}
return toReturn;
}
return toReturn;
}
//parent at root node?
TArray<UObjectAttribute*> UDatabaseManager::listObjectChildrensWithRoot(FString name, FXmlNode * parent) {
TArray<UObjectAttribute*> toReturn;
if (fileLoaded) {
FXmlNode* target = parent->FindChildNode(name);
if (target != nullptr) {
TArray <FXmlNode*> characteristics = target->GetChildrenNodes();
for (FXmlNode* node : characteristics) {
UObjectAttribute * newAttb = NewObject<UObjectAttribute>();
if (node->GetChildrenNodes().Num() > 0) { // has children
for (FXmlNode* child : node->GetChildrenNodes()) {
UObjectAttribute * temp = NewObject<UObjectAttribute>();
temp->attbName = child->GetTag();
if (child->GetChildrenNodes().Num() > 0) {
temp->childs = listObjectChildrensWithRoot(child->GetTag(),node);
}
else {
temp->attbValue = child->GetContent();
}
newAttb->childs.Add(temp);
}
}
newAttb->attbName = node->GetTag();
newAttb->attbValue = node->GetContent();
toReturn.Add(newAttb);
}
}
return toReturn;
}
return toReturn;
}
Blueprint debugger:
Can anyone help me?