Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by GutoThomas · Jun 26, 2012 at 12:57 AM · xml.exe

XML reading working in Editor but not in compiled executable

 Platform assembly: C:\Users\Guto\Desktop\test_Data\Managed\System.Core.dll (this message is harmless)
 Platform assembly: C:\Users\Guto\Desktop\test_Data\Managed\System.Xml.dll (this message is harmless)
 Platform assembly: C:\Users\Guto\Desktop\test_Data\Managed\System.dll (this message is harmless)
 IsolatedStorageException: Could not find a part of the path "C:\Users\Guto\Desktop\Assets\DEAD ZONE ANDROID\Languages\arachnaZone_EN.xml".
   at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0 
 
   at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in <filename unknown>:0 
 
   at System.Xml.XmlUrlResolver.GetEntity (System.Uri absoluteUri, System.String role, System.Type ofObjectToReturn) [0x00000] in <filename unknown>:0 
 
   at Mono.Xml2.XmlTextReader.GetStreamFromUrl (System.String url, System.String& absoluteUriString) [0x00000] in <filename unknown>:0 
 
   at Mono.Xml2.XmlTextReader..ctor (Boolean dummy, System.Xml.XmlResolver resolver, System.String url, XmlNodeType fragType, System.Xml.XmlParserContext context) [0x00000] in <filename unknown>:0 
 
   at System.Xml.XmlTextReader..ctor (Boolean dummy, System.Xml.XmlResolver resolver, System.String url, XmlNodeType fragType, System.Xml.XmlParserContext context) [0x00000] in <filename unknown>:0 
 
   at System.Xml.XmlReader.Create (System.String url, System.Xml.XmlReaderSettings settings, System.Xml.XmlParserContext context) [0x00000] in <filename unknown>:0 
 
   at System.Xml.XmlReader.Create (System.String url, System.Xml.XmlReaderSettings settings) [0x00000] in <filename unknown>:0 
 
   at System.Xml.XmlReader.Create (System.String url) [0x00000] in <filename unknown>:0 


This is the error I get in the outputLog. Everything works fine in the Editor, but no in the executable. The error occurs in both Windows and Android.

Here are the paths for the .xmls:

alt text

And here, if necessary is the code which actually returns the string attached to a individual attribute:

 public string[] getTexts (Attributes attribute) {
     
 XmlReader reader = XmlReader.Create( xmlPaths[ (int)_curLanguage ] );
 int textQuantity = 0;
 string[] texts = null;


     while( reader.Read () ) {
         
         if( reader.IsStartElement( attribute.ToString( ) ) ) {
             
                 textQuantity = int.Parse( reader.GetAttribute( "quantity") );
                 texts = new string[textQuantity];
             
                     for(int i = 0; i < textQuantity; i++) {
                 
                         reader.Read();
                 
                             if(reader.IsStartElement(attribute.ToString() + "Tag")) {
                             
                                 texts[i] = (string)reader.ReadString();
                     
                             }
                 
                     }
             
             }
         
     }
 
     return texts;
 
 }



Any help would be very appreciated! Thanks from now!

paths.png (52.7 kB)
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

2 Replies

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

Answer by whydoidoit · Jun 26, 2012 at 01:01 AM

That's not how you would get hold of the files on the device - in a build those files will not exist. You need to either put them in a Resources folder and read them as a TextAsset using Resources.Load - or you could place them in Streaming Assets and get them using that path on the device (or copy them manually into a location during your build). Your Assets... path isn't going to exist on the build though - so you will need to adjust all of those depending on the approach you take.

Comment
Add comment · Show 6 · 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 GutoThomas · Jun 26, 2012 at 01:12 AM 0
Share

Yep. Great point! If I just let the .xml in the Resource folder, they'll stay accessable during the game execution? Because I don't know what type holds and .xml file to get it from Resources.Load(..);

avatar image GutoThomas · Jun 26, 2012 at 01:29 AM 0
Share

Ok, I could load them using the Strea$$anonymous$$gAssets folder path combined with the file name, now it works in the executable! Thanks!

avatar image GutoThomas · Jun 26, 2012 at 01:39 AM 0
Share

Unfortunatelly, when I tested it in the mobile, the error persists. The code is the following:

 void Awake () {
     
     _language$$anonymous$$anager = this;
     DontDestroyOnLoad(this);
     
     string strea$$anonymous$$gAssets = Application.strea$$anonymous$$gAssetsPath;
     
     languageFiles = new string[3];
     languageFiles[0] = System.IO.Path.Combine(strea$$anonymous$$gAssets, "arachnaZone_EN.xml");
     languageFiles[1] = System.IO.Path.Combine(strea$$anonymous$$gAssets, "arachnaZone_PTBR.xml");
     languageFiles[2] = System.IO.Path.Combine(strea$$anonymous$$gAssets, "arachnaZone_SN.xml");
     
     
 }



In the mobile, I get the following path for the file:

jar:file:///data/app/DeadZone.bunker-1.apk/!/assets/arachnaZone_EN.xml

avatar image whydoidoit · Jun 26, 2012 at 07:19 AM 0
Share

Sorry to be a while getting back to you. Yes on droid the strea$$anonymous$$g assets is compressed into a JAR file so you can't just open it with System.IO (I forgot that, sorry, it's fine on IOS which I use most of the time ).

avatar image whydoidoit · Jun 26, 2012 at 07:21 AM 0
Share

You can get it from Resources.Load like this:

     var textAsset = Resources.Load("Path", typeof(TextAsset)) as TextAsset; //Rename the file to .txt and no extension here
     var myText = textAsset.text;
Show more comments
avatar image
0

Answer by carterdawson · Jun 30, 2016 at 05:20 PM

As an adjunct to @whydoidoit's answer:

Read the documentation on streaming assets, and you'll see that you need to use the WWW class to fetch the files if you are using Android. System.IO works fine otherwise.

Note that WWW is asynchronous, so you'll need to use Coroutines to kick off the download and wait until it's done. This can be a little bit of a dragon, since on some platforms (Windows, IOS), this will be a file:// url, and it will complete in one frame on those platforms, so if you don't actually wait until the Coroutine finishes, you can end up with subtle bugs that can be really un-obvious to track down when they happen.

So, the best practice there is probably to use WWW, but that means you'll need to turn your function (and any function that calls it, and any function that calls any of those functions, etc. etc.) into a coroutine. Basically, this means that if you have something like this:

 void Start() {
   process_file_sysio("file.name.txt")
 }

 private List<int[]> process_file_sysio(string filename)
 {
     List<int[]> lai_ret;
     System.IO.StreamReader file = new System.IO.StreamReader(filename);

     lai_from_file_contents(file, lai_ret);
     return lai_ret;
 }

You'll need to turn it into this:

 IEnumerator Start() {
   List<int[]> lai = new List<int[]>();
   yield return process_file_sysio("file.name.txt");
 }

 private IEnumerator process_file_sysio(string filename, List<int[]> lai_ret)
 {
     System.IO.StreamReader file = new System.IO.StreamReader(filename);

     lai_from_letter_contents_str(file, lai_ret);
     yield return null;
 }

Note that I needed to do two changes. First, I had to make process_file_sysio return an IEnumerable instead of a List. Obviously, I can't return lai_ret from that function anymore, so I moved it into the parameters. Then, I had to do the same thing to Start, which calls the function. Make it return IEnumerable, and change the function call to be a "yield return".

Now, of course, all I've done is to replicate what I had before, but I'm still using System.IO, which is a problem. The whole point is to migrate to WWW. All I need to do that is to create a process_file_www() function, like this:

 IEnumerator Start() {
   List<int[]> lai = new List<int[]>();
   yield return process_file_www("file.name.txt");
 }

 private IEnumerator process_file_www(string filename, List<int[]> lai_ret)
 {

     WWW w = new WWW("file://" + filename);
     yield return w;

     StringReader file = new StringReader(w.text);
     lai_from_letter_contents_str(file, lai_ret);
 }

The function process_file_www is a drop-in replacement for process_file_sysio now that we've Coroutine-enabled everything, so this method will work regardless of the platform. You could even put the file on the internet, and download it that way, and your application will still work (it will just be a little slower).

The last gotcha: It's easy to forget to change the original function call to "yield return". If you do that, you'll get the strange behavior I refer to earlier, where a single frame's worth of your function gets called, but subsequent frames don't. Watch out for that.

I also found this answer on stackoverflow that has an interesting trick to turn the Coroutine into a callback. It doesn't really buy you anything, but it might be helpful if callbacks are more understandable to you than Coroutines are.

Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

read object name and transformation from max 0 Answers

A node in a childnode? 1 Answer

Serializing and Deserializing from/to XML inside Resources folder 1 Answer

How To Switch A XmlNodeList To A String 1 Answer

Declaring XML Namespace at Runtime 1 Answer


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