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 · Aug 10, 2015 at 08:10 AM · androidunity5xml

Reading XML Data for andriod

Hi,

I created an application and it works perfectly on my windows laptop but when I build and run it on my android device it has an issue. When I run on my android the integer and decimal data are showing as 0, while my string data is coming out fine. This is the way I am loading my data.

This is the fruitObj class containing the properties. While the fruit container is used to serialize and deserialize the fruit data from my XML File.

public class FruitObj {

  [XmlAttribute("name")]
  public string Name;
  public int AmountPer;
  public int Calories;
  public decimal TotalFat; }

[XmlRoot("FruitCollection")] public class FruitContainer { [XmlArray("Fruits")] [XmlArrayItem("Fruit")] public List Fruits = new List();

  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; } }

Below is my script where I initialize my fruit data to UI Text. As you can see I am loading my XML file from Script folder (found in the asset directory). UI Text variables are being initialized from the Scene

public class AppleNutritionalFacts : MonoBehaviour { bool visible; FruitObj AppleInfo; Text titleText; Text amountPerText; Text caloriesText; Text totalFatText;

  void Awake()
  {
      visible = true;
      AppleInfo = new FruitObj();
      List fruitList = new List();
      // var fruitCollection = FruitContainer.Load(Path.Combine(Application.dataPath,

@"Scripts\NutrionArXML.xml")); FruitContainer fc = FruitContainer.Load(Path.Combine(Application.dataPath, @"Scripts\NutrionArXML.xml")); fruitList = fc.Fruits;

      foreach (FruitObj fo in fruitList)
      {
          if (fo.Name.ToLower().Equals("apple"))
          {
              AppleInfo = fo;
          }
      }
  }
  // Update is called once per frame
  void Update()
  {
       if (AppleInfo != null)
      {
          string title = "<b>" + AppleInfo.Name + "

Nutritional Facts"; string amountPer = "Amount per " + > AppleInfo.AmountPer + "g"; string calories = "Calories: " + AppleInfo.Calories + "";

          string totalFat = "<b>Total Fat:</b> " +

AppleInfo.TotalFat + "g\t" + AppleInfo.TotalFatPcnt + "%";

          titleText.Text = title;
      amountPerText.text = title;
      caloriesText.Text = title;
     totalFatText.Text = title;
      }
  } }


Do you have any idea what I am doing wrong please?

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
0

Answer by infuzo · Aug 10, 2015 at 09:00 AM

Use XMLDocument, XMLNode, XMLElement, its very simple instrument to work with XML for any system.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity/Google Play Games set up Android. Error 0 Answers

Unity5 Android mip-mapping problem 1 Answer

Parse and Unity5 for android broke? 1 Answer

Is Build and Run essential to make a Gear VR app ? 1 Answer

Artifacts while using google vr sdk 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