- Home /
Help a noob parse an xml file
I didn't really want to put this here but I really don't understand all of this. I understand xml, but parsing it in C# is the problem. I searched on unity forums and answers but the almost all the solutions I found were either outdated or I didn't understood a single line of the code.
In my game I have a 5x5 grid, blue, green and grey blocks. The blocks are placed on the grid according to my xml file. This is an example of level 40: (0 means no block, 1 means a grey block, 2 means a blue block and 3 means a green block)
<levels>
<level id="40">
<row id="1">
<col id="1">1</col>
<col id="2">0</col>
<col id="3">0</col>
<col id="4">0</col>
<col id="5">3</col>
</row>
<row id="2">
<col id="1">3</col>
<col id="2">0</col>
<col id="3">1</col>
<col id="4">0</col>
<col id="5">2</col>
</row>
<row id="3">
<col id="1">2</col>
<col id="2">0</col>
<col id="3">0</col>
<col id="4">1</col>
<col id="5">0</col>
</row>
<row id="4">
<col id="1">0</col>
<col id="2">0</col>
<col id="3">1</col>
<col id="4">0</col>
<col id="5">0</col>
</row>
<row id="5">
<col id="1">0</col>
<col id="2">1</col>
<col id="3">0</col>
<col id="4">0</col>
<col id="5">0</col>
</row>
</level>
</levels>
I will have a script that loops through the rows and columns given in the file to place the right blocks in the right place. But first I need to know how the script will select the right level and columns also with the id="" parameter. Making a loop shouldn't be that big of a problem for me but parsing the data is.
I really hope someone can help me on this. Thanks in advance.
Answer by HarshadK · Aug 18, 2015 at 01:53 PM
Here's a tutorial on how it can be done: XML - Loading data from a xml file
Not much of an explanatory tutorial but the code from that page has logic and methods that you will require to parse your XML file.
I'm still trying to get my head around it but I'll get it eventually. I'm probably better of learning it like this as well.
Your answer
Follow this Question
Related Questions
Handle HTML response 0 Answers
Parseing Varible names from strings 1 Answer
Retrive value from xml 1 Answer
Parse xml with unknown fields 1 Answer
Parsing an XML file periodically 2 Answers