I've been able to create an xml file using linq, using this code:
XElement config =
new XElement("Configurations",
new XElement("configuration",
new XAttribute("mode", 1),
new XElement("Platform",
new XAttribute("name", "Device Portal")),
new XElement("IPConfigurations",
new XAttribute("IPmode", eS_IPsettings1.IPMode),
new XAttribute("IPAddress", eS_IPsettings1.IPAddress),
new XAttribute("NetMask", eS_IPsettings1.NetMask),
new XAttribute("GateWay", eS_IPsettings1.Gateway)),
new XElement("ProxyConfigurations",
new XAttribute("ProxyMode", eS_ProxySettings1.Enable),
new XAttribute("ProxyURL", eS_ProxySettings1.ProxyURL)),
new XElement("KeyLockConfigurations",
new XAttribute("KeyLockMode", eS_KeyLock1.Enable),
new XAttribute("Pin", eS_KeyLock1.Pin))
)
);
which produces xml files like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Configurations>
<configuration mode="1">
<Platform name="Device Portal" />
<IPConfigurations IPmode="Keep existing" IPAddress="..." NetMask="..." GateWay="..." />
<ProxyConfigurations ProxyMode="Keep existing" ProxyURL="Enter proxy URL here" />
<KeyLockConfigurations KeyLockMode="Keep existing" Pin="" />
</configuration>
</Configurations>
Now I want to check the attribute value of configuration, and based if the value is 1, I want to parse the attribute values of the child elements in this configuration. What is the best approach to do so?
I've tried it using LoadXml, but I couldn't figure out how to make that work... I think the best way to read the file is using linq but i have no clue how.