- Home /
Load xml from resources (uri is too long)
Until now I was loading the xml files from StreaminAssets, but I want to hide the files to prevent theft. (gathering the data is time consuming and valuable as it's a first in the genre)
But what is the proper way to load an xml from Resources?
With the help of some other topics about xml in the resources folder I came to this:
TextAsset xmlFile = Resources.Load<TextAsset>("Airports/Europe");
var doc = new XmlDocument();
doc.Load(xmlFile.text); // <- error happens here
XmlElement root = doc.DocumentElement;
XmlNodeList airportsList = root.SelectNodes("//airport");
But this gives me the following error:
Invalid URI: The Uri string is too long.
I guess my file is too long, but I'm sure there is a way around this?
if the data is so valuable consider using a server to use the xml data, resources.asset file can be easily uncompress, there are plenty of tutorials on how to uncompress it (without hacking knowledge at all)
Thanks for letting me know. I thought it was irreversible.
I suggest you read up on the documentation. The Load function expects a URI, an identifier, not the text itself.
Answer by Tjoeker · Nov 17, 2020 at 02:55 PM
I found the solution. It's quite simple actually. (not sure why the other posts didn't do this.)
This line:
doc.Load(xmlFile.text);
Should be:
doc.LoadXml(xmlFile.text);
Your answer
![](https://koobas.hobune.stream/wayback/20220613015948im_/https://answers.unity.com/themes/thub/images/avi.jpg)