I'm looking for a better way to parse XML data

Subscribe to I'm looking for a better way to parse XML data 8 posts

avatar for AMD_Paulius_J AMD_Paulius_J 110 posts
Flag Post

Right now I have an XML tile map in this format

<tile>b1</tile>
<tile>b1</tile>
<tile>t2</tile>
<tile>t2</tile>
<tile>t2</tile>
<tile>t2</tile>

Well it’s only a part of it, it actually is more than 1000 rows. And I parse it like this:

var mapTiles:XMLList = new XMLList();
var xml:XML;

xml = new XML(xmlLoader.data);
mapTiles = xml.tile.children();

for(var a:int = 0; a < mapTiles.length(); a++)
	{
		testingArray[a] = mapTiles.text()[a]; //Looping through array and adding values
	}

But well, I believe it is not a very effective method, the question is:

if I had an XML file like this:

<tile>b1, b1, t2, t2, t2, t2, t2, t2</tile>

How would i parse it? How could I insert into array each element separated by “,”?

 
avatar for vesperbot vesperbot 1849 posts
Flag Post

I guess this isn’t an XML problem, but rather a problem of forming and navigating the original file. IIRC XML does not allow arrays in such a form, so I say stick with what works.

 
avatar for AMD_Paulius_J AMD_Paulius_J 110 posts
Flag Post

Hmm, maybe that’s why I couldn’t find any proper documentation on this, all articles are for web developers, and they don’t have tileMaps:)

 
avatar for Kewry Kewry 98 posts
Flag Post

have you taken a look at JSON? it could ease up the trouble seeing as data comes in arrays

 
avatar for AMD_Paulius_J AMD_Paulius_J 110 posts
Flag Post
Originally posted by Kewry:

have you taken a look at JSON? it could ease up the trouble seeing as data comes in arrays

Well yes, I read a lot about JSON it’s a lot better than XML, but I’m not good enough yet to implement JSON, so this time I’m going with XML.

 
avatar for Draco18s Draco18s 6860 posts
Flag Post

Technically you CAN store an array in that manner. Just read in the one node as a string, then do:

var myArrayObjects:Array = myXMLstring.split(",");
 
avatar for AMD_Paulius_J AMD_Paulius_J 110 posts
Flag Post

Hmm, I will try that, thanks.

 
avatar for FantasyJam FantasyJam 52 posts
Flag Post

You should look at how other people read XML files from Ogmo editor and similar data. All of it has a structure of some kind. Draco has already given you the appropriate code for your situation, though. The split() function is very useful.