xmltextreader

import System.Xml;

myXmlReader = new XmlTextReader(“http://myserver/unityTest/test2.xml”);

I have been trying to load xml into unity to display in a GUI using javascript but i get the following error. What am I doing wrong?

NotSupportedException: http://myserver/unitytest/test2.xml
System.Net.WebRequest.GetCreator (System.String prefix)
System.Net.WebRequest.Create (System.Uri requestUri)
System.Xml.XmlUrlResolver.GetEntity (System.Uri absoluteUri, System.String role, System.Type ofObjectToReturn)
Mono.Xml2.XmlTextReader.GetStreamFromUrl (System.String url, System.String absoluteUriString)
Mono.Xml2.XmlTextReader…ctor (System.String url, System.Xml.XmlNameTable nt)
System.Xml.XmlTextReader…ctor (System.String url, System.Xml.XmlNameTable nt)
System.Xml.XmlTextReader…ctor (System.String url)
getCareerSector.getCareerInfo () (at C:\3D\unity\3DPlatformerTutorial\Assets\Scripts\data\getCareerSector.js:83)
getCareerSector.OnMouseDown () (at C:\3D\unity\3DPlatformerTutorial\Assets\Scripts\data\getCareerSector.js:14)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UnityEngine.MouseOverPair:SendMessage(String) (at C:\builds\unity-trunk\unity\Runtime\Export\MouseEvents.cs:17)
UnityEngine.SendMouseEvents:smile:oSendMouseEvents() (at C:\builds\unity-trunk\unity\Runtime\Export\MouseEvents.cs:118)

Hello Gateway,

If you’re using this code in the webplayer, hoping that it will load the XML because it’s on the same server, I got good news and bad news for you :smile:

Bad news is that it won’t work this way.

Good news is that there’s a solution. I encountered the same problem a while ago and Matthew from Flashbang Studios was kind enough to point me in the right direction.

What you need to do is use the TextAsset functions in the Unity API to load the XML, then convert that to a byte array, using which you can create a MemoryStream, which is accepted by the constructor of the XmlTextReader. It is a bit convoluted but it works.

Let us know how it goes.
-Yilmaz

Thanks, although I am actually experimenting with pulling xml data from a webservice and thought I would start with an xml file.