Xml loading issue

I’ve a problem with loading xml file. That’s what i do:

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

public class prova : MonoBehaviour {

	public TextAsset gs;
	private XmlDocument dom;

	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update () {
		dom.LoadXml (gs.text);
	}
}

And that’s what unity tell me:
NullReferenceException: Object reference not set to an instance of an object
prova.Update () (at Assets/prova.cs:18)

I initialize variable gs in the Inspector

You also need to initialize the dom object, and dont call dom.LoadXML in Update trying to load an XML every frame doesnt sound like a good idea :slight_smile:

Try this in Start

void Start()
{
   dom = new XmlDocument();
   dom.LoadXML(gs.text);
}

ahah what a stupid issue. Thank you!

You’re welcome :slight_smile: