Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by SeanM3D · Nov 23, 2015 at 05:41 PM · webglxmlstreamingassetsxmlserializerdeserialize

Deserializing XML not working with WebGL

Hallo everyone,

I am trying to create a working WebGL version of my application. To do so I need to deserialize an XML file called hspositions.xml, located in the StreamingAssets directory. This works fine in the Editor and Standalone, but not in WebGL. Right now I’m only testing locally with Firefox.

I already asked the question on the forum, but no solution came up so far.

What is left are two error messages showing in the Firefox Browser Console, that I can't get rid of:

Error: WebGL: texImage2D: invalid typed array type for given texture data type WebGL.js:1

and

"IsolatedStorageException: Could not find a part of the path "/file:/D:/Unity_Projects/Axion800_Kabine_DebugWebGL/WebGL/StreamingAssets/hspositions.xml". " WebGL.js:1

Here is my DataCollection class which contains the class structure to store the deserialized XML content as well as the DeSerialize() method:

 [XmlRoot("Data")]
 public class DataCollection
 {
     [XmlElement("Hotspot")]
     public Hotspot[] Hotspot = new Hotspot[24];
 
     public static DataCollection DeSerialize(string path)
     {
         XmlSerializer serializer = new XmlSerializer(typeof(DataCollection));
 
         using(var stream = new FileStream(path, FileMode.Open))
         {
             return serializer.Deserialize(stream) as DataCollection;
         }
     }
 }
 
 public class Hotspot
 {
     [XmlElement("Properties")]
     public Properties[] Properties= new Properties[360];
 }
 
 public class Properties
 {
     public float xPos;
     public float yPos;
 
     public float alphaValue;
 }


And here is my XMLDeserializer class that calls the DeSerialize() method:

 public class XMLDeserializer : MonoBehaviour 
 {
     public static DataCollection XmlData;
 
     public static string filePath;
 
     public static string result = "";
 
 
     IEnumerator Example()
     {
         if(filePath.Contains("://"))
         {
             WWW www = new WWW(filePath);
             yield return www;
             result = www.url;
 
             XmlData = DataCollection.DeSerialize(result);
         }
         else 
         {
             XmlData = DataCollection.DeSerialize(filePath);
         }
     }
     void Awake () 
     {
         filePath = Path.Combine(Application.streamingAssetsPath, "hspositions.xml");
 
         StartCoroutine("Example");
     }
 }

As the documentation suggests, I am using the WWW class to extract the filePath in the case of a URL.

Can anyone give me a hint into the right direction?

Thanks a lot!

Sean

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

Answer by SeanM3D · Nov 24, 2015 at 12:10 PM

Found a solution for reading the XML file when it's in the StreamAssets folder. That works locally in Firefox. See #9 here:

http://forum.unity3d.com/threads/loading-xml-from-streamassets-not-working.369564/#post-2394650

Before finding that solution I used a workaround with Resources.Load. For details see posting #8 here:

http://forum.unity3d.com/threads/loading-xml-from-streamassets-not-working.369564/#post-2394650

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

37 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

Related Questions

xml file read as MonsterCollection.cs 0 Answers

Read XML file and assign value to variables 0 Answers

Unity game doesn't work after binding 0 Answers

How to load specific data from XMLArray 0 Answers

Issues with reading XML file from StreamingAssets on Android! 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