read XML in webapp

I’m trying to make an application where the user is able to click on a building to get information about it.
This information should be loaded from a XML-file (so the content can be adjusted).

What is the best way to do this?

My current findings on the forum:

  • importing system.xml add too much kbytes
  • using WWW can give errors, hence this article .

So what’s the best practive here?

Hey Spiky,

I had the same problem happen to me when I was developing my PuzzleOps game. I had an XML file that contained information about objects in my level and I needed to load it in the webplayer.
However, I did use import system.xml.

Here’s how I did it:
-Import your XML file as an asset and put it in the Resources folder.
-In your script that’s going to load and read the XML file, add this code:

var XMLfile : TextAsset  = UnityEngine.Resources.Load("puzzles");
var reader : XmlTextReader = new XmlTextReader(new MemoryStream(XMLfile.bytes));

-Once you’ve done this, you can read the XML file from the XMLTextReader as you normally would. An example is:

while (reader.Read())
	{
	    switch (reader.NodeType)
	    {
	        case XmlNodeType.Element: // The node is an element.
etc...

I hope this helps.

Putting the XML file in resources doesn’t help him being able to dynamically change it, and XmlTextReader is part of System.Xml which he specifically said he didn’t want to use. Don’t mean to be disrespectful, but did you just see the word XML, stop reading, and spit out your experiences with XML?

My advice to the OP would actually be to not use XML, but use your own format and write your own parser. It’s not hard for most purposes to create a format that’s as human-readable as XML but much easier for scripts to parse. For example:

BuildingName=Something
Description=Something else
Occupancy=300
Height=100
~
BuildingName=Something2
Description=Something else
Occupancy=300
Height=100

You can use String.Split(char) to split this file up and read it and your final script will be small enough to use in a Webplayer.

I managed to read XML through the webpage:
-contact the webpage with a searchvalue as argument
-javascript on the webpage handles the call and searches in an xml-file
-when the search is complete, the webpage contacts the unity webapp with the result as argument
-webapp handles the call and displays the result

This way I can make the xml files as large and complex as I want, and maybe implement a CMS in the future.

But my unity trial key expired :frowning: