Skip to content
Andrey Pepper edited this page Mar 29, 2026 · 4 revisions

An XML parser will appear in the system, and here's how to use it

  1. Default:
string xml = "<user><name>admin</name><password>1234</password></user>";

var doc = new NanoXMLDocument(xml); 
var root = doc.RootNode; 

Console.WriteLine("Root: " + root.Name); //<user>

Console.WriteLine("Name: " + root["name"].Value);
Console.WriteLine("Password: " + root["password"].Value);

while (true);
  1. With attributes:
string xml = "<user id='1' role='admin'></user>

var doc = new NanoXMLDocument(xml); 
var root = doc.RootNode; 

var idAttr = root.GetAttribute("id"); 
var roleAttr = root.GetAttribute("role");

Console.WriteLine("Root: " + root.Name); //<user>

Console.WriteLine("ID: " + idAttr.Value);
Console.WriteLine("Role: " + roleAttr.Value);
  1. Tree Search (Find):
string xml = "<user><name>admin</name><password>1234</password></user>";

var doc = new NanoXMLDocument(xml); 
var root = doc.RootNode;
var found = root.Find("password");

Console.WriteLine("Found password: " + found.Value);
  1. Load for file:
protected override void BeforeRun()
{
    Console.Clear();
    var fs = new CosmosVFS();
    VFSManager.RegisterVFS(fs);
    File.Create(@"0:\device.xml");
    File.WriteAllText(@"0:\device.xml", "<root xmlns='urn:schemas-upnp-org:device-1-0'>\r\n<specVersion>\r\n<major>1</major>\r\n<minor>0</minor>\r\n</specVersion>\r\n<device>\r\n<deviceType>urn:schemas-upnp-org:device:MediaRenderer:1</deviceType>\r\n<friendlyName>[LG] SMART TV LH570V$</friendlyName>\r\n<manufacturer>LG Electronics.</manufacturer>\r\n<modelName>LG TV</modelName>\r\n<modelNumber>4.0</modelNumber>\r\n<UDN>uuid:e6fac687-fea8-dd45-6ead-0ebe9f66d62b</UDN>\r\n<serviceList>\r\n<service>\r\n<serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType>\r\n</service>\r\n<service>\r\n<serviceType>urn:schemas-upnp-org:service:RenderingControl:1</serviceType>\r\n</service>\r\n</serviceList>\r\n</device>\r\n</root>");
}

protected override void Run()
{
    try
    {
        var doc = NanoXMLDocument.LoadFromFile(@"0:\device.xml");
        var root = doc.RootNode;

        var device = root["device"];

        Console.WriteLine("Name: " + device.GetValue("friendlyName"));
        Console.WriteLine("Model: " + device.GetValue("modelName"));
        Console.WriteLine("Manufacturer: " + device.GetValue("manufacturer"));
        Console.WriteLine("Version: " + device.GetValue("modelNumber"));

        Console.WriteLine("--- Services ---");

        var services = device["serviceList"];
        if (services != null)
        {
            foreach (var s in services.SubNodes)
            {
                Console.WriteLine(s.GetValue("serviceType"));
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("ERROR: " + ex.Message);
    }

    while (true) ;
}

Clone this wiki locally