private const string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<byme_configuration xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:noNamespaceSchemaLocation=""BymeConfiguration.xsd"" hash=""c8e5503c11208a185b3be4b874d4350e"" lang=""en"" timestamp=""1643969200"">
<root_environment id=""0"" label=""House"">
<environment id=""3"" label=""First Floor"">
<environment id=""1"" label=""Kitchen""/>
<environment id=""2"" label=""Living Room""/>
<environment id=""4"" label=""Second Floor"">
<environment id=""5"" label=""Bathroom""/>
<environment id=""6"" label=""Bedroom""/>
<application id=""0"" label=""Light"" environment_id=""1"" category_id=""1"" category=""lights"" channel_id=""0"" channel=""ON - OFF light"">
<group id=""1"" label=""Group"">
<group_address address=""0x0C01"" flags=""W"" >
<dpt id=""1.001"" name=""DPT_Switch"" /> <!-- vimar_id not present, it is a standard datapoint -->
<dptx id=""1"" name=""DPTx_OnOff""/>
<group_address address=""0x0EC9"" flags=""RT"" >
<dpt id=""1.001"" name=""DPT_Switch"" /> <!-- vimar_id not present, it is a standard datapoint -->
<dptx id=""75"" name=""DPTx_OnOffInfo""/>
<application id=""1"" label=""Thermostat"" environment_id=""6"" category_id=""4"" category=""climate control"" channel_id=""2"" channel=""Heating and Air Conditioning"">
<group id=""1"" label=""Thermostat Group"">
<group_address address=""0x0C3F"" flags=""W"" >
<dpt id=""20.102"" vimar_id=""60000.60076"" name=""DPT_Vimar_HVACMode"" /> <!-- vimar_id present, it is a custom datapoint, id is the nearest one -->
<dptx id=""212"" name=""DPTx_HvacMode""/>
<group_address address=""0x0C40"" flags=""RT"" >
<dpt id=""20.102"" vimar_id=""60000.60076"" name=""DPT_Vimar_HVACMode"" /> <!-- vimar_id present, it is a custom datapoint, id is the nearest one -->
<dptx id=""213"" name=""DPTx_HvacModeInfo""/>
<group_address address=""0x0C41"" flags=""W"" >
<dpt id=""9.001"" name=""DPT_Value_Temp"" /> <!-- vimar_id not present, it is a standard datapoint -->
<dptx id=""214"" name=""DPTx_TemperatureSetpoint1""/>
<group_address address=""0x0C42"" flags=""RT"" >
<dpt id=""9.001"" name=""DPT_Value_Temp"" /> <!-- vimar_id not present, it is a standard datapoint -->
<dptx id=""215"" name=""DPTx_TemperatureSetpointInfo1""/>
<group id=""2"" label=""Output Group 2"">
<group_address address=""0x0C6A"" flags=""T"" >
<dpt id=""1.001"" name=""DPT_Switch"" /> <!-- vimar_id not present, it is a standard datapoint -->
<dptx id=""1"" name=""DPTx_OnOff""/>
<group_address address=""0x0C6B"" flags=""T"" >
<dpt id=""5.010"" vimar_id=""60000.60083"" name=""DPT_Vimar_Fancoil_2T"" /> <!-- vimar_id present, it is a custom datapoint, id is the nearest one -->
<dptx id=""248"" name=""DPTx_Fancoil2Pipes""/>
public static void Main() {
XmlTextReader reader = null;
Console.Write("===========================================================================\n");
Console.Write("================================ Parse and list ========================\n");
Console.Write("===========================================================================\n");
reader = new XmlTextReader(new System.IO.StringReader(xml));
reader.WhitespaceHandling = WhitespaceHandling.None;
switch (reader.NodeType) {
case XmlNodeType.Element:
Console.Write("Element: <{0}>\n", reader.Name);
Console.Write(reader.Value);
Console.Write("Text: <![CDATA[{0}]]>\n", reader.Value);
case XmlNodeType.ProcessingInstruction:
Console.Write("ProcessingInstruction: <?{0} {1}?>\n", reader.Name, reader.Value);
case XmlNodeType.Comment:
Console.Write("Comment: <!--{0}-->\n", reader.Value);
case XmlNodeType.XmlDeclaration:
Console.Write("XmlDeclaration: <?xml version='1.0'?>\n");
case XmlNodeType.Document:
case XmlNodeType.DocumentType:
Console.Write("DocumentType: <!DOCTYPE {0} [{1}]\n", reader.Name, reader.Value);
case XmlNodeType.EntityReference:
Console.Write(reader.Name);
case XmlNodeType.EndElement:
Console.Write("EndElement: </{0}>\n", reader.Name);
Console.Write("===========================================================================\n");
Console.Write("================================== XPath ===============================\n");
Console.Write("===========================================================================\n");
XmlDocument doc = new XmlDocument();
doc.Load(new System.IO.StringReader(xml));
XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes(".//environment");
Console.Write("XmlNodeList: {0} environments\n", nodes.Count);
foreach (XmlNode node in nodes) {
Console.Write("XmlNode: {0} id={1} name={2}\n", node.Name, node.Attributes["id"].Value, node.Attributes["label"].Value);