XML File - Step 1?

Hey guys, this is my last hurdle to begin creating my game. I use Json saving and Java, so my XML knowledge is non-existant and all the tutorials seem to assume too much and begin with “just import this code > code”

Im using a plug-in tool, “Dialoguer” and i simply need an XML file to save a string variable, the command to save and everything is already present with the tool, its simply getting an XML file and interacting with it in unity which i dont know about.

So, What are the first steps to get an XML file into unity? (Does unity have the option or do i need visual studio?)

Thanks plenty

You need to write code to read and write files in Unity.

This article about Saving Data#2 which uses XmlSerializer might be helpful for you.

You store your XML file from where you want to access it (preferably Assets folder) and then you access that XML file as you would access any other file from code.

The part from that tutorial where it loads and reads the XML file is as below:

To read from a file we just need to
create an instance of XmlSerializer
specialised to the root of our XML

var xmlSerializer = new XmlSerializer();

Now we need to provide that serializer
with the data from a stream - if you
have a file you just open it:

var stream = File.Open("somefile.xml");

If we have a string then we might use

var stream = new MemoryStream
(Encoding.UTF8.GetBytes (xml)); Then
to create our entire structure we just

var library = xmlSerializer.Deserialize(stream);

And that’s it - we’ve got the whole
thing loaded. You should remember to
close any File you’ve opened of

There is also an article on Unity Wiki about Saving and Loading Data: XmlSerializer

Before you jump right into something, I would suggest you to read those articles carefully. :slight_smile: