Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Neyona1992 · Apr 10, 2021 at 01:26 PM · androidxml

Can't find XML file

Hello, I want to read a XML file in Android but I can't find the XML file in APK file. When I build the app I get a error: NotSupportedException: The URI prefix is not recognized.

Filepath is: Assets/StreamingAssets/Diller/ceviri-tr.xml

Code:

 void Start()
 {
     XmlDocument doc = new XmlDocument();
     doc.Load(Application.streamingAssetsPath + "/Diller/ceviri-tr.xml");
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Apr 10, 2021 at 01:36 PM

You can't directly access streaming assets with normal File I/O as those assets are not actual files in the file system but are packed inside your APK file. You can read about that in the StreamingAssets manual page.


On platforms like Android and WebGL you can only read the streaming assets by using a UnityWebRequest and provide it with a special URI that is returned by Application.streamingAssetsPath.

You have to use the "LoadXml" method instead of "Load" and pass it the content of the xml file which you loaded with the UnityWebRequest. Note that the streaming assets are readonly on Android and WebGL builds. If you want to be able to modify the file, you have to copy the file to the persistent data path if the file does not exist yet and work on that copy instead.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Neyona1992 · Apr 10, 2021 at 03:31 PM 0
Share

Hello, thanks for you answer now I can read XML file but I still get a error: XmlException: Data at the root level is invalid. Line 1, position,1.

Code:

 void Start()
 { 
       var webrequest = UnityWebRequest.Get(Application.strea$$anonymous$$gAssetsPath + "/Diller/ceviri-tr.xml");
       webrequest.SendWebRequest();
       doc.LoadXml(webrequest.downloadHandler.text);
 }

XML file:

 <ceviri>
   <startbutton>Başla</startbutton>
   <levels>Seviyeler</levels>
   <menu>Menü</menu>
   <mermi>Mermi: </mermi>
 </ceviri>
avatar image Bunny83 Neyona1992 · Apr 10, 2021 at 07:47 PM 0
Share

Well, that's a different issue, but a common one ^^. The Xml parser does not like a BOM (Byte Order Mark) at the file start. Some text editors (especially notepad) adds a BOM even when the encoding is utf8 which does not need and does not recommend to add one. Anyways, the XmlParser can't handle the BOM. The best solution is to just remove the BOM from your file. Most text editors do support different encoding formats. Even notepad does support utf8 with and without BOM. So just open your file in notepad, click save as and choose just UTF8 as encoding (not with BOM) and then try again.


There are other solutions like pulling the bytes through a StringReader which should also remove the BOM as the BOM is not really a printable character.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

261 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I use a custom Android Manifest? 2 Answers

XmlWriter.Create exception, "Could not find the file..." on Android 0 Answers

XML Manifest: Unity and Android 1 Answer

PlayerPrefs file wrong stored location 0 Answers

xml/network_sec_config not found 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges