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
0
Question by haider1515 · Nov 02, 2011 at 01:11 PM · xmlparser

Xml parser through C sharp

   <color>Green</color>
   <score>1000</score>
   <size>2</size>

   <color>RED</color>
   <score>1000</score>
   <size>1.5</size>
  

   <color>Blue</color>
   <score>1000</score>
   <size>1</size>
   

this is my xml file i want to get the the score values using UnityEngine; using System.Collections; using System.Xml;

public class Parsing : MonoBehaviour {

 public static int[] Values=new int[3];
 void Start()
 {
     XmlDocument newone=new XmlDocument();
     newone.Load("new.xml");
     XmlNodeList xnlist1=newone.SelectNodes("/spheres/sphere1/score");
     XmlNodeList xnlist2=newone.SelectNodes("/spheres/sphere2/score");
     XmlNodeList xnlist3=newone.SelectNodes("/spheres/sphere3/score");
 

     foreach(XmlNode xn1 in xnlist1)
     {
     
         Values[0]=int.Parse(xn1.InnerText);
     }
     foreach(XmlNode xn2 in xnlist2)
     {
         Values[1]=int.Parse(xn2.InnerText);    
     }
     foreach(XmlNode xn3 in xnlist3)
     {
         Values[2]=int.Parse(xn3.InnerText);    
     }

     
     Debug.Log(Values[0]);
     Debug.Log(Values[1]);
     Debug.Log(Values[2]);
  
 }
 
 

 

} this parsing i m doing its working correct in unity but when i build it and try to run on web my Values[0],Values[1] and Values[2] goes to 0.... if anyone can help me....

Comment
Add comment · Show 2
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 haider1515 · Nov 02, 2011 at 12:47 PM 0
Share

   <color>Green</color>
   <score>1000</score>
   <size>2</size>

   <color>RED</color>
   <score>1000</score>
   <size>1.5</size>
  

   <color>Blue</color>
   <score>1000</score>
   <size>1</size>
   

avatar image gfr · Nov 02, 2011 at 01:21 PM 0
Share

You need to use code formatting for xml to show properly. Also, see http://answers.unity3d.com/questions/139834/how-do-i-load-an-xml-file.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by It_is_hot_in_vegas · Oct 09, 2017 at 01:32 AM

I know I'm late, but the reason why this does not work is because the script is telling the program to save/read data from your computer, but when you run it on a web player(HTML, etc.), that ability to read/write usually becomes disabled. This happens because anti-virus software is preventing this read/write connection from being made, or the fact that the script is telling the program to load from/ save to an undefined location. Through this method, the program usually reads from/writes to the project folder. Since there's no project folder when published to the web, the program has trouble looking for that specified file. Your best bet would be to add these values to your script.

Here's an example I made:

 //starting values
 public string ColorName = "Green"
 public int Score = 1000;
 public float Size =2f;
 
 public int Condition = 1; //We will be using a condition just for this example.
 
 //changing them later
 
 void Update(){ //Update checks for any changes.
 if (Condition == 1){  //looks like this because Unity answers doesn't allow the tab key.
 ColorName = Green
 public int Score = 1000;
 public float Size =2f;
 }
 if (Condition == 2){
 ColorName = Red
 public int Score = 1000;
 public float Size =1.5f;
 }
 if (Condition == 3){
 ColorName = Blue
 public int Score = 1000;
 public float Size =1f;
 }

It may not be what you are going for, but it's the best I can answer this question.

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

Using JSON to get tree data into JavaScript objects 3 Answers

Parsing and displaying KML 0 Answers

XML parser, how to get to 1 of many elements with the same name. 1 Answer

XML to Custom Asset Parser, cant get the code to work when refactored 0 Answers

Run script before run 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