Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 xanawa · Jul 29, 2015 at 11:54 AM · unity 5errorxml

xml loading in unity andriod

Hi I created an XML file containing the data of 3 fruits. I imported the XML file in Assets/Scripts folder now I am trying to connect to it and retrieve the data using the following code. I followed this example http://wiki.unity3d.com/index.php?title=Saving_and_Loading_Data:_XmlSerializer

  public class FruitObj : MonoBehaviour {
     
         [XmlAttribute("name")]
         public string Name;
     
         public int Sugar;
         public decimal Protein;
     }
     
     [XmlRoot("FruitCollection")]
     public class FruitContainer
     {
         [XmlArray("Fruits")]
         [XmlArrayItem("Fruit")]
         public List<FruitObj> Monsters = new List<FruitObj>();
     
     
         public static FruitContainer Load(string path)
         {
             var serializer = new XmlSerializer(typeof(FruitContainer));
             using (var stream = new FileStream(path, FileMode.Open))
             {
                 return serializer.Deserialize(stream) as FruitContainer;
             }
         }
     
         //Loads the xml directly from the given string. Useful in combination with www.text.
         public static FruitContainer LoadFromText(string text)
         {
             var serializer = new XmlSerializer(typeof(FruitContainer));
             return serializer.Deserialize(new StringReader(text)) as FruitContainer;
         }
     }

and I am trying to connect in my gameobject using

 public class AppleNutritionalFacts : MonoBehaviour
 {
 
     void Start()
     {
         var fruitCollection = FruitContainer.Load(Path.Combine(Application.streamingAssetsPath, "NutrionArXML.xml"));
     }
 }


Then I am getting this erroralt text

Can anyone please tell me what im doing wrong?

error.png (240.0 kB)
Comment
Add comment · Show 3
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 xanawa · Jul 29, 2015 at 10:11 AM 0
Share

I will try it and give you feedback, thx :)

avatar image Hellium · Jul 29, 2015 at 10:19 AM 2
Share

FruitObj should not inherits from $$anonymous$$onoBehavior, sorry.

avatar image darthtelle · Jul 29, 2015 at 12:51 PM 0
Share

I'm unfamiliar with this method of reading X$$anonymous$$L in Unity unfortunately. But if you are continuing to hit a roadblock with your current approach (don't give up yet!!), there are alternative methods of importing X$$anonymous$$L. I've included a couple of links that were helpful for me. They're beginner level, but you can easily build them up and tailor them to your project. Just in case!

https://web.archive.org/web/20140702084233/http://unitygems.com/xml/ http://unitynoobs.blogspot.co.uk/2011/02/xml-loading-data-from-xml-file.html http://blog.sokay.net/2012/08/14/loading-xml-in-unity-building-a-stage-from-xml/

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xanawa · Jul 30, 2015 at 07:31 AM

I removed mono behavior and it worked thanks helium

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity 5 UNet Spawn as Child. 1 Answer

IO Exception: Sharing Violation on Path,IOExeption Sharing Violation on Path 0 Answers

Help "Too many threads" 0 Answers

The name 'TrackManager' does not exist in the current context [Unity Vuforia Ground Plane Project] 0 Answers

Shader worked in Unity 4.5, now Unity 5 kills it. 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