Announcement

Collapse
No announcement yet.

XML Parsing Project works on PC Editor but not Android Devices

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    XML Parsing Project works on PC Editor but not Android Devices

    Hi, I am encountering an issue with my android apk not reading contents from my XML file. The entire project worked fine on the editor and there is no packaging error. Managed to Logcat the problem and zeroed down the error. Here is the parsing part of the code.

    Code:
    std::string MyString(TCHAR_TO_UTF8(*(FPaths::GameDir() + "Content/XMLFiles/TestRead.xml")));
    std::ifstream file(MyString.c_str());
    std::stringstream buffer;
    buffer << file.rdbuf();
    file.close();
    std::string content(buffer.str());
    UE_LOG(YourLog, Warning, TEXT("contents of xml: %s"), *FString(content.c_str())); //<- This prints out the entire XML content fine on editor
    doc.parse<0>(&content[0]);
    It seems like the Android device is not reading the XML file. I have check the obb and the XML file is stored in "Content/XMLFiles/TestRead.xml" of the game directory. So the XML file is indeed packaged within.

    Click image for larger version

Name:	XMLA.png
Views:	1
Size:	4.2 KB
ID:	1216307

    The Editor printed the content

    Click image for larger version

Name:	XMLB.png
Views:	1
Size:	10.2 KB
ID:	1216308

    But the packaged file failed to print the content.

    I am relatively new to mobile development and wish someone could shed some light on this matter. Much help is appreciated.

    #2
    You could do this with:

    Code:
    FString MyFilePath = FPaths::GameContentDir() + TEXT("XMLFiles/TestRead.xml");
    FString Contents;
    if (FFileHelper::LoadFileToString(Contents, *MyFilePath))
    {
       // do something with *Contents
    }
    Make sure you mark XMLFiles directory to be packaged as "Additional Non-Asset Directories to Package" in the Packaging Project Settings (you need to expand the Packaging section to see it).

    Comment


      #3
      Hi Chris!

      It worked! Thanks for the help! Do I have to update this thread to solved?

      Comment

      Working...
      X