• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Trouch · Jul 02, 2014 at 05:44 AM · savexmlsavingdialogue

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by HarshadK · Jul 02, 2014 at 07:07 AM

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 structure.

  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 this:

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

  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 course.

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. :-)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Trouch · Jul 02, 2014 at 07:20 AM 0
Share

Thanks, although to obtain the initial X$$anonymous$$L file, how do i do that? Do i convert an empty C# or Java script file into being an X$$anonymous$$L file or do i need to create an X$$anonymous$$L file and import it into unity?

avatar image HarshadK · Jul 02, 2014 at 07:41 AM 1
Share

You create an X$$anonymous$$L file (create a file with extension .xml) and then import it into Unity.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trouble updating old Unity syntax 0 Answers

Write to XML-file within Assets\Resources 1 Answer

How to store a variable after quit? (iOS) 4 Answers

Load XML File ? 1 Answer

Saving Data! PLEASE HELP 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges