O'Reilly logo

Unity 4.x Cookbook by Matt Smith, Chico Queiroz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating XML text data manually using XMLWriter

One way to create XML data structures from game objects and properties is by hand-coding a method to create each element and its contents, using the XMLWriter class.

How to do it...

To create XML text data using XMLWriter, follow these steps:

  1. Add the following C# script to Main Camera:
    // file: CreateXMLString.cs using UnityEngine; using System.Collections; using System.Xml; using System.IO; public class CreateXMLString : MonoBehaviour { private string output = "(nothing yet)"; private void Start () { output = BuildXMLString(); } private void OnGUI() { GUILayout.Label( output ); } private string BuildXMLString() { StringWriter str = new StringWriter(); XmlTextWriter xml = new XmlTextWriter(str); // start ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required