Hi everyone, new Unity pro user here, just started a new project.
I’m having some trouble with the usage of System.Xml on the web player.
For my project, I need to read a big XML file (over 4MB in size!) from an online server, parse it and use the data to build geometries.
I tried first using some of the XML Parser scripts other people posted on this forum, and they work fine, however the parsing is amazingly slow (minutes for such huge XML files).
Then I tried importing System.XML and it’s amazingly fast! Parses in less than a second the same files! The code works great on standalone Windows, Mac and Android (didn’t try iPhone yet). However the web player seems to ignore LoadXml()
So if I do something like
import System.Xml;
class XmlDataLoader
{
var GuiData:String;
var www:WWW;
var activeXml:XmlDocument;
var xmlData:String = "";
var guiText:String = "";
var XmlIsLoaded:boolean = false;
function LoadObjectXML(xml:String)
{
XmlIsLoaded = false;
www = new WWW(xml);
}
function OnGUI ()
{
var textrect = Rect (10, 10, 220, 150);
if (GuiData) GUI.TextArea( textrect, GuiData );
}
function Update()
{
if (this.www !XmlIsLoaded)
{
GuiData = "Downloading XML... "+(Mathf.Round(this.getProgress()*1000)/10).ToString()+"% done"+"\n"+evLoader.guiText;
this.Update();
}
if (!XmlIsLoaded www.isDone )
{
XmlIsLoaded = true;
xmlData = www.text;
buildObjectsFromData();
}
}
function getProgress()
{
if(www)
{
return www.progress;
}
else
{
return -1;
}
}
function buildObjectsFromData()
{
guiText+="Parsing...";
activeXml = new XmlDocument();
if (xmlData)
{
guiText+= "\nThe file exists and has "+xmlData.length+" characters\n";
activeXml.LoadXml(xmlData);
}
else
{
guiText+="\nNo XML data!!!!";
}
guiText+="\nParsing complete";
//Then use the data for whatever
}
}
(This is based on my actual code, but not all of it nor exactly like it. Serves for illustration of the problem only)
If then I create a XmlDataLoader object and make it load an XML posted online trough LoadObjectXML(url), it should:
-Load it, displaying a GUI text indicating the progress
-Call buildObjectsFromData(). Display “Parsing…”. Validate the existence of the string correspondent to the XML, and display its number of characters (this is for debug purposes, for me to be sure the XML was really loaded). Then parse the XML. Then display “Parsing complete”. Then use the data
All of this works fine in every build platform except the web player. It gets to verify the existence of the XML string data, displaying its number of characters (in test versions I even made it display the first 200 characters, just to make sure it was really reading the file correctly!)… And then… Nothing. It never gets to display “Parsing complete”.
However I have a few objects in the scene, and a camera controller, and it’s possible to keep flying around. So it’s not frozen! Only it never gets to parse.
Anyone has a clue on what may be happening?
Thanks!