As being a Flash Developer for many years,I’m very used to just quickly loading and parsing an external XML file. Although this is possible with Unity,I found out there’s very limited information about this subject available in a Unity context. While investigating this subject a while ago,I also decided to look into the JSON format as a data container,to see which works best for me. Naturally I’d prefer to use XML over JSON,but it turns out that both comes with their cons and pros,which makes it hard to say which works best.
In this two part tutorial I’ll show how you could load an XML or JSON file into Unity and parse it’s information. Both the XML file and JSON file are containers for the same information,which makes it easier to compare the differences between the two.
XML
The XML file I’ve created contains a couple of books. In order to cover different ways to work with XML,it contains a variety of data,like attributes,regular nodes and childnodes,integers,strings and CDATA blocks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?
xml
version
=
"1.0"
?>
<
books
>
<
book
id
=
"1"
>
<
title
>Papervision3D Essentials</
title
>
<
image
>http://paultondeur.com/files/2010/UnityExternalJSONXML/Papervision3DEssentials.jpg</
image
>
<
authors
>
<
author
id
=
"1"
>Paul Tondeur</
author
>
<
author
id
=
"2"
>Jeff Winder</
author
>
</
authors
>
<
description
>
<![CDATA[<p>Create interactive <b>Papervision3D</b> applications with stunning effects and powerful animations</p>]]>
</
description
>
</
book
>
<
book
id
=
"2"
>
<
title
>Unity Game Development Essentials</
title
>
<
image
>http://paultondeur.com/files/2010/UnityExternalJSONXML/UnityGameDevelopmentEssentials.jpg</
image
>
<
authors
>
<
author
id
=
"3"
>Will Goldstone</
author
>
</
authors
>
<
description
>
<![CDATA[<p>Build fully functional,professional 3D games with realistic environments,sound,<i>dynamic effects</i>,and more!</p>]]>
</
description
>
</
book
>
</
books
>
|