- Home /
XmlException: Text node cannot appear in this state
Before I get into the issue, I'm aware there is another question that sounds exactly the same as mine. However, I've tried that solution (using Notepad++ to encode the xml file as UTF-8 (without BOM) ) and it doesn't work.
XmlDocument namesDoc = new XmlDocument();
XmlDocument factionsDoc = new XmlDocument();
namesDoc.LoadXml(Application.persistentDataPath + "/names.xml");
factionsDoc.LoadXml(Application.persistentDataPath + "/factions.xml");
Above is the code I have problems with. I'm not sure what the problem is.
<?xml version="1.0" encoding="UTF-8"?>
<factions>
<major id="0">
...
Above is a section of the XML file (the start of it - names.xml is also the same except it has no 'id' attribute). The file(s) are both encoded in UTF-8 - in the latest notepad++ version, there is no option of "encode in UTF-8 without BOM" afaik UTF-8 is the same as UTF-8 without BOM.
Does anyone have any idea what the cause may be? Or am I doing something wrong/forgetting something? :/
This comment comes so late, but this post was incredibly helpful. Thanks, @Neo$$anonymous$$uro !
Answer by NeoKuro · Oct 25, 2015 at 05:06 PM
So I just figured out the issue.
Encoding IS correct however I was using the wrong function to load the file.
I used;
namesDoc.LoadXml(Application.persistentDataPath + "/names.xml");
what I should have used;
namesDoc.Load(Application.persistentDataPath + "/names.xml");
something about LoadXml() expecting xml data, whereas Load() is expecting the path to the file to load
Thought I'd answer in case someone else has an issue like this :)
Answer by BornaFana · Aug 06, 2017 at 09:59 AM
Hey @NeoKuro, I know this is super late, but where do you put this Code? Is it attached to an empty in your scene or what? I'm new to Unity, especially for android games. Could you help?
PS: I already tried converting for UTF-8 on N++, no luck. Thanks :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612042655im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UTF-8 characters on Android build 1 Answer
FileMode.Create an encoded xml file in UTF-8 1 Answer
How can I read an XML file in Android ? I can't access it 1 Answer
xml look a node with a certain value. 0 Answers
Bake/embed XML into exe 0 Answers