UnityUtilities
|
The XmlHelper serializes and deserializes to/from XML and allows convenient access to optional element content and attributes when reading general XMLs. More...
Static Public Member Functions | |
static XmlSerializer | GetSerializer< T > () |
Gets a cached XmlSerializer for the specified type. More... | |
static string | SerializeToXmlString< T > (this T data) |
Uses the XmlSerializer to serialize data into a string that can later be deserialized again via DeserializeFromXmlString<T>. More... | |
static T | DeserializeFromXmlString< T > (this string str) |
Deserializes an object serialized with SerializeToXmlString<T>. More... | |
static string | GetElementString (this XmlNode xmlNode, string name, string defaultValue="") |
Gets the content of first child element with the specified name. If no child with that name exists, the defaultValue is returned. More... | |
static int | GetElementInt (this XmlNode xmlNode, string name, int defaultValue=0) |
Gets the content of first child element with the specified name. If no child with that name exists, the defaultValue is returned. More... | |
static float | GetElementFloat (this XmlNode xmlNode, string name, float defaultValue=0) |
Gets the content of first child element with the specified name. If no child with that name exists, the defaultValue is returned. More... | |
static bool | GetElementBool (this XmlNode xmlNode, string name, bool defaultValue=false) |
Gets the content of first child element with the specified name. If no child with that name exists, the defaultValue is returned. More... | |
static string | GetAttributeString (this XmlNode xmlNode, string name, string defaultValue="") |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned. More... | |
static int | GetAttributeInt (this XmlNode xmlNode, string name, int defaultValue=0) |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned. More... | |
static int | GetAttributeIntNullable (this XmlNode xmlNode, string name, int? defaultValue=null) |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned. More... | |
static float | GetAttributeFloat (this XmlNode xmlNode, string name, float defaultValue=0) |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned. More... | |
static float | GetAttributeFloatNullable (this XmlNode xmlNode, string name, float? defaultValue=null) |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned. More... | |
static bool | GetAttributeBool (this XmlNode xmlNode, string name, bool defaultValue=false) |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned. More... | |
The XmlHelper serializes and deserializes to/from XML and allows convenient access to optional element content and attributes when reading general XMLs.
|
static |
Deserializes an object serialized with SerializeToXmlString<T>.
T | Thedata type that was serialized. |
str | The serialized data string. |
InvalidOperationException | An error occurred during deserialization. The original exception is available using the InnerException property. |
|
static |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned.
xmlNode | The XMlNode to get the attribute from. |
name | The name of the attribute. |
defaultValue | The default value if no attribute with that name exists. |
FormatException | The content is is not in the correct format. |
|
static |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned.
xmlNode | The XMlNode to get the attribute from. |
name | The name of the attribute. |
defaultValue | The default value if no attribute with that name exists. |
FormatException | The content is is not in the correct format. |
OverflowException | The content represents a number less than MinValue or greater than MaxValue. |
|
static |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned.
xmlNode | The XMlNode to get the attribute from. |
name | The name of the attribute. |
defaultValue | The default value if no attribute with that name exists. |
FormatException | The content is is not in the correct format. |
OverflowException | The content represents a number less than MinValue or greater than MaxValue. |
|
static |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned.
xmlNode | The XMlNode to get the attribute from. |
name | The name of the attribute. |
defaultValue | The default value if no attribute with that name exists. |
FormatException | The content is is not in the correct format. |
OverflowException | The content represents a number less than MinValue or greater than MaxValue. |
|
static |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned.
xmlNode | The XMlNode to get the attribute from. |
name | The name of the attribute. |
defaultValue | The default value if no attribute with that name exists. |
FormatException | The content is is not in the correct format. |
OverflowException | The content represents a number less than MinValue or greater than MaxValue. |
|
static |
Gets the content of first attribute with the specified name. If no attribute with that name exists, the defaultValue is returned.
xmlNode | The XMlNode to get the attribute from. |
name | The name of the attribute. |
defaultValue | The default value if no attribute with that name exists. |
|
static |
Gets the content of first child element with the specified name. If no child with that name exists, the defaultValue is returned.
xmlNode | The XMlNode to get the child from. |
name | The name of the child. |
defaultValue | The default value if no child with that name exists. |
FormatException | The content is is not in the correct format. |
OverflowException | The content represents a number less than MinValue or greater than MaxValue. |
|
static |
Gets the content of first child element with the specified name. If no child with that name exists, the defaultValue is returned.
xmlNode | The XMlNode to get the child from. |
name | The name of the child. |
defaultValue | The default value if no child with that name exists. |
FormatException | The content is is not in the correct format. |
OverflowException | The content represents a number less than MinValue or greater than MaxValue. |
|
static |
Gets the content of first child element with the specified name. If no child with that name exists, the defaultValue is returned.
xmlNode | The XMlNode to get the child from. |
name | The name of the child. |
defaultValue | The default value if no child with that name exists. |
FormatException | The content is is not in the correct format. |
OverflowException | The content represents a number less than MinValue or greater than MaxValue. |
|
static |
Gets the content of first child element with the specified name. If no child with that name exists, the defaultValue is returned.
xmlNode | The XMlNode to get the child from. |
name | The name of the child. |
defaultValue | The default value if no child with that name exists. |
|
static |
Gets a cached XmlSerializer for the specified type.
T | The type to get the XmlSerializer for. |
|
static |
Uses the XmlSerializer to serialize data into a string that can later be deserialized again via DeserializeFromXmlString<T>.
With a few exceptions (e.g. arrays of ArrayList and arrays of List<T>), all public attributes and fields of any public class should be serialized without any further need to tag the elements. The only thing needed is a public default constructor.
For finer control, see the MSDN document on XmlSerializer: https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer(v=vs.110).aspx
T | The data type to be serialized. |
data | The data to be serialized. |