Load and Display XML Data in Unity 3D

Advertisemen





Load and Display XML Data in Unity 3D

This video will show you, how to read or display XML file in unity 3d. In this example we use local source of xml file (inside Unity folder) but If you want to use file from the server, follow my other tutorial on how to load file from external server and combine it together.

https://www.youtube.com/watch?v=Go-FfepGETs



Code used in this tutorial ( C# ) :

using UnityEngine;
using System.Collections;
using System.IO;
using System.Xml;
using UnityEngine.UI;

public class loadXmlFile : MonoBehaviour 
{
    public TextAsset xmlRawFile;
    public Text uiText;

    // Use this for initialization
    void Start () 
    {
        string data = xmlRawFile.text;
        parseXmlFile (data);
    }

    void parseXmlFile(string xmlData)
    {
        string totVal = "";
        XmlDocument xmlDoc = new XmlDocument ();
        xmlDoc.Load ( new StringReader(xmlData));

        string xmlPathPattern = "//aarlangdi/aarstaff";
        XmlNodeList myNodeList = xmlDoc.SelectNodes (xmlPathPattern);
        foreach(XmlNode node in myNodeList)
        {
            XmlNode name = node.FirstChild;
            XmlNode addr = name.NextSibling;
            XmlNode phone = addr.NextSibling;

            totVal += " Name : "+name.InnerXml+"\n Address : "+ addr.InnerXml+"\n Mobile : "+phone.InnerXml+"\n\n";
            uiText.text = totVal;
        }
    }
}

Thanks for watching.
Please don't forget to subscribe, like, comment and share.


Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D