SpriteLibrary
SpriteLibrary
SpriteLibrary
SpriteDatabase Class
SpriteDatabase Methods
CloneByXMLSerializing(T) Method
GetImageFromName Method
GetImageNames Method
LoadObjectFromXmlFile(T) Method
OpenEditWindow Method
ReadFromXmlFile(T) Method
ReadFromXmlString(T) Method
Save Method
SetIcon Method
SetSnapGridSize Method
SpriteFromName Method
SpriteNames Method
WriteToXmlFile(T) Method
WriteToXMLString(T) Method

# SpriteDatabase WriteToXmlFile T Method

Writes the given object instance to an XML file. Only Public properties and variables will be written to the file. These can be any type though, even other classes. If there are public properties/variables that you do not want written to the file, decorate them with the [XmlIgnore] attribute. Object type must have a parameterless constructor.

Namespace: SpriteLibrary
Assembly: SpriteLibrary (in SpriteLibrary.dll) Version: 1.0.0.6 (1.0.0.6)
Syntax
C#
Copy

    public static void WriteToXmlFile<T>(
    	string filePath,
    	T objectToWrite
    )
    where T : new()

#### Parameters

filePath
  Type: System
  String
  The file path to write the object instance to.
objectToWrite
  Type: T
  The object instance to write to the file.

#### Type Parameters

T
  The type of object being written to the file.

Examples
XML Serialization takes an object (a class, a variable, or whatever) and will store any public values in XML. You can choose to save the resulting XML as a string, or to save it to a file. This function writes to a file that is outside of Properties.Resources; the resources of a program are read-only. Once you write to a file, you can drag the resulting XML into your project and load it from there. If you want to load from an XML file that is not a resource, use ReadFromXmlFile
T
(String)

Here is code to create an item and save it to a file.
Copy

    MyClass MyVariable = new MyClass();
    MyVariable.Name = "StoreThis!";

    SpriteDatabase.WriteToXmlFile<MyClass>("c:\xml_file.xml", MyClass);

Now that we have an XML file, we can use this code to load it.
Copy

    MyClass MyVariable = SpriteDatabase.ReadFromXmlFile<MyClass>("c:\xml_file.xml");
    Console.WriteLine(MyVariable.Name);

See Also

#### Reference

SpriteDatabase Class
SpriteLibrary Namespace