Loading XML causes game freeze

How would you load an XML file without locking up the whole game interface?

at the moment my code is like this. It compiles fine and does its job. Its just it takes a few seconds before anything can animate again.

var xmldoc = new System.Xml.XmlDocument();
   
    	var iospath : String = Application.dataPath.Substring (0, Application.dataPath.Length - 5);
		iospath = iospath.Substring(0, iospath.LastIndexOf("/"));
		iospath = iospath + "/Documents";
	
		var fileFullName : String;
    	
    	
    	fileFullName = iospath + "/MinorItem.xml";

	    if (!File.Exists(fileFullName)) {
	   
	 		//Debug.Log ("File not exists");  
	   
	   		var tWWW = new WWW("https://whatever.com/xml/xmlGetMinorItem.asp"); 
	   		yield tWWW; 
	 
	 		Debug.Log(tWWW.text);
	 
	 		var swtr : StreamWriter = new StreamWriter(fileFullName);
	
			Debug.Log(swtr.Encoding);
			
	   		swtr.Write(tWWW.text);
	   		swtr.AutoFlush = true;
	   		swtr.Close();
	
	   		Debug.Log ("File exists:" + File.Exists(fileFullName)) ;  		 
	   }
   
		   var srdr : StreamReader = File.OpenText(fileFullName);
		   var xmlString : String = ""; 
		   
		   xmlString = srdr.ReadToEnd();
		   
		   xmldoc.LoadXml(xmlString);
		       
		   var node : System.Xml.XmlNode;   
		   var nodeList : System.Xml.XmlNodeList;
		   
		   nodeList= xmldoc.SelectNodes(GalleryXMLPath);
		   
		   var t : GameObject;
		   var sname : String;
		   var productcode : String;
		   var textData :TextMesh;
		   
		   node = nodeList.ItemOf[0];
  		
  			var iTotal : Int16 = int.Parse(node.Item["TOTALPAGES"].InnerText);
  			
  			PagesCount = iTotal ;
	
}

Loading an XML-file is not a task that requires Unity API, so you’re free to multithread it. You can make the XmlDocument a class variable, then move the code that calls its LoadXml-function into a different function, then start a thread that executes that function. This will load your XML and leave the mainthread free to keep rendering frames at the same time.

See also Parsing large XML files on-the-fly, best practice? - Questions & Answers - Unity Discussions