Cover by Matt Smith, Chico Queiroz

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required