blog games developers documentation portfolio gallery

More in this category:

SimpleXML

Import any XML string into Unity at runtime. The results are formatted as a hierarchy of good old Hashtables and ArrayLists.

No fancy stuff, no nonsense, just an Importer and a few extensions to the existing C# Hashtable and ArrayList classes. It also doesn't start throwing exceptions the second the XML isn't 100% according to standards.

I said no fancy stuff, but I lied. There are a few extra functions:
- import only a subsection (by tag)
- export as XML
- export as JSON
- find node at path
- find node by property value
You can test it all if you run the Demo scene that is included. Or you can run the demo here.

To obtain the SimpleXML package, go to the Unity Asset Store

To use SimpleXML in your Unity project, you need to have the files SimpleXmlImporter.cs and SimpleXmlExtensions.cs somewhere in your project folder.

Some code examples:

// import an XML string
bool caseInsensitive = false;
myHashtable = SimpleXmlImporter.Import(xmlString, caseInsensitive);

// import only the tag named "materials"
myHashtable = SimpleXmlImporter.Import(xmlString, "materials");

// export as JSON
string jsonString = myHashtable.JsonString();

// query the hierarchy
selectedNode = myHashtable.GetNodeWithProperty("author", "George Orwell");


More functions for accessing members can be found here and here.








follow us