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 rishabhvinod · Sep 04, 2013 at 08:55 AM ·

how can i parse xml through API in unity please can anyone explain with some example.

I am trying to parse an XML through API . XML is loading but unable to read nodes of the xml, please can anyone help me with some suitable example from which i can read nodes of my XML and display in GUI.

Thanks in advance

Comment
Add comment · Show 1
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 rishabhvinod · Sep 04, 2013 at 10:07 AM 0
Share

please guys help me out....

2 Replies

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

Answer by rishabhvinod · Sep 04, 2013 at 12:27 PM

Hi Guys i got the solution and i am shring with you all for reference....

using System.Collections; using UnityEngine; using System.Xml.Serialization; using System.Xml; using System.Collections.Generic; using System.IO; using System;

public class newLoad : MonoBehaviour {

 private string _url = "your API or url of xml";

 private string _xml;
 Vector2 scrollPosition = Vector2.zero;
 XmlDocument xmlDoc = new XmlDocument();
 List<Dictionary<string,string>> levels = new List<Dictionary<string,string>>();
 Dictionary<string,string> obj;
 ArrayList listItems = new ArrayList();
 
 IEnumerator Start() {

      // Start a download of the given URL

     WWW www = new WWW(_url);
     
 
     // Wait for download to complete

     yield return www;
     
     // get text

     _xml = www.text;

     
     XmlDocument xmlDoc = new XmlDocument();
      xmlDoc.LoadXml(www.text);

      Debug.Log(_xml);
     print(xmlDoc);

     // having XML here. Do with it whatever you want...
             
     XmlNodeList levelsList = xmlDoc.GetElementsByTagName("MainCategories");
     
     foreach (XmlNode levelInfo in levelsList)
       {
         //Debug.Log("foreach inner");
         string str = levelInfo.InnerXml;
            XmlNodeList levelcontent = levelInfo.ChildNodes;
            obj = new Dictionary<string,string>();
     //    Debug.Log("MainCategories = " + str);
     
         foreach (XmlNode levelsItens in levelcontent)
            {
             //Debug.Log("~~~~~~First Node~~~~~");
             Dictionary<string,string> obj1 = new Dictionary<string,string>();
             if(levelsItens.Name == "MainCategory")
             {
                 //Debug.Log("~~~~~~Second Node~~~~~");
                 string str1 = levelsItens.Name;
                  obj1.Add("MainCategory",levelsItens.InnerText);
             //    Debug.Log("MainCategory = " + str1);
         
                 foreach (XmlNode levelsItens1 in levelsItens)
                    {
                     //Debug.Log("~~~~~~Third Node~~~~~");                        
                     Dictionary<string,string> obj2 = new Dictionary<string,string>();
                     if(levelsItens1.Name == "MainCategoryID")
                     {
                         string str2 = levelsItens1.InnerXml;
                          obj2.Add("MainCategoryID",levelsItens1.InnerText);
                         Debug.Log("MainCategoryID = " + str2);
                     }
                     if(levelsItens1.Name == "MainCategoryTitle")
                     {
                         string str3 = levelsItens1.InnerXml;
                          obj2.Add("MainCategoryTitle",levelsItens1.InnerText);
                         Debug.Log("MainCategoryTitle = " + str3);
                         
                         if(str3 != "NULL"){
                             
                             listItems.Add(str3);
                         }
                         
                     }                    
                 }
             }    
         }
     }
 }

 void OnGUI () {
     
    GUILayout.BeginArea(new Rect(0f, 0f, 300f, 200f), GUI.skin.window);
    scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true); 
    GUILayout.BeginVertical(GUI.skin.box);
 
    foreach (string item in listItems)
    {
      GUILayout.Label(item, GUI.skin.box, GUILayout.ExpandWidth(true));
    }
 
    GUILayout.EndVertical();
    GUILayout.EndScrollView();
    GUILayout.EndArea();
 }
 
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
avatar image
0

Answer by sooncat · Sep 04, 2013 at 10:34 AM

Import System.xml.dll in "Assets/Plugins" folder.

By the way, xmlDll is too big somtime. Json may be a better choice.

Comment
Add comment · Show 1 · 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 rishabhvinod · Sep 04, 2013 at 11:00 AM 0
Share

@sooncat thanx for reply.. but i have System.xml.dll in my "Assets/Plugins" folder.

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

17 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

Related Questions

accessing a variable from one script in another with Unity 1 Answer

GUI.Textfield in unity. adding a "what's on your mind" like function 1 Answer

Collider for road track in Unity3d car tutorial 0 Answers

I have two buttons in my c# script, i want to make invissible one button and make it vissible on click of another button at runtime. Can anyone please show me the way for the proper solution. 1 Answer

how to show data in same gui layout..?? 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