I’m using C# with the Mono System.XML classes. I’m reading an XML file without a problem when running standalone. But when running in the web player, it doesn’t work at all. Does anyone know if this is a limitation in the XML implementation in the web player? Here’s a code fragment…
XmlTextReader reader = new XmlTextReader("map.xml");
while (!reader.EOF)
{
reader.Read ();
...
}
My XML file is in the same folder as my Unity executable so it couldn’t be a path issue. Any other ideas?
Ok, thanks. I’m not sure I understand what you mean by “data from WWW.” Do you just mean to use binary data instead of a string? Or do you mean to use a URL at which the XML data resides? Would I be able to use XmlTextReader at all. Can you elaborate.?
No with that I mean that you put your XML on a webserver and request it from there.
then you would read out the content of the xml from the www.data field and use it for xml parsing.
If System.Xmls reader can read a string instead of a file is something you would have to check. I’m sure in one form or the other it also parses strings.
Sorry, I’m not sure what you mean. My path is simply “map.xml”, which refers to a file in the same folder on the webserver as my .unity3d file. How would I specify those paths differently than XmlTextReader(“map.xml”)? Would I use something like XmlTextReader(“http://mysite/map.xml”)? Or maybe I need to embed the XML in an HTML file? Or could it be that my webserver doesn’t like the XML MIME type?
You seem to forget that when the webplayer runs it does not run on your webserver at all but on the client.
What zumwalt wants to explain to you is that you basically must tell the webplayer exactly where to look for it (Application.absoluteUrl etc are of use)
unsure if using that directly there though works, you will have to test. if it doesn’t you can always download the content of the xml and use that
What about using the XML as an embedded resource? I tried something like this but even though it works standalone, it doesn’t seem to work in the web player:
TextAsset rawData;
rawData = (TextAsset) Resources.Load("map");
reader = new XmlTextReader(new StringReader(rawData.text));
while (!reader.EOF reader.NodeType != XmlNodeType.EndElement)
{
reader.Read();
...
}
stringreader is System.IO too, so potentially the same restrictions
The System.IO namespace is considerably reduced for webplayers, anything that relies on files directly or indirectly.
System.XML is one of those namespaces that unhappily heavily rely on file but also on marshaling which is both not allowed on the webplayer, so there are parts of it that do not work.
System.XML is due to this heavy degree of dependencies also pretty heavy on the filesize. It makes the webplayer over 1mb larger, the iphone binary suffers similarily both due to the requirement that System is included in the build, not only the mscorelib
Actually, I did get it to work in the web player. It looks like I had branched my code to read a URL. But when I changed it to using an embedded XML resource, as in the standalone build, it worked.
Very nice! So, XmlTextReader will read a bundled xml resource? Cool! At that point, were you able to use “map.xml” without a prefix?
Thanks in advance!
if its bundled it ceases to be an xml, it will become a textasset which you can load and parse.
and url would work too but U3 requires the crossdomain.xml to be present to access anything but files in a place relative to the webplayer and relative paths only.
And you would naturally need to download it first through WWW cause the integrated ways in .NET won’t work, they are forbidden in the webplayer (either io or webrequest)
@dreamora:
What would you recommend to parse XML, or perhaps just some custom data format, in a webplayer situation?
I have a parser I wrote in C++ which would work in Pro on iPhone, but wouldn’t likely work in a web-based case without porting to C#, yes?
I re-read your comment about System being a huge file, and so am now thinking I could write some kind of simple markup (non-xml) and just parse it using regular file io (if that is possible in Web case).