I’m trying to do something, that may be extremely simple so please bear with me, I just want to get an Attribute from an XML file into a string in my C# code. here’s what I have:
XML:
<MonitorResponseRecord Enabled="false" DisplayName="ValveFailureAtCentralPosition">
<ExpressionMonitor>
<AlarmName>Valve_Position_Fault</AlarmName>
<Parameter> Sensor Position = {X}</Parameter>
</ExpressionMonitor>
</MonitorResponseRecord>
<MonitorResponseRecord ... ... ...>
... ...
... ... and so on about 1600 times.
C#:
[Selrializable]
[XmlType("Alarm")]
public class AlarmDefinition
{
public AlarmDefinition() {}
public AlarmDefinition Clone()
{
AlarmDefinition clone = new AlarmDefinition();
clone.DisplayName = DisplayName;
clone.Category = Category;
clone.Color = Color;
clone.Description = Description;
return clone;
}
[XmlAttribute( ??????????? )] public string DisplayName = "";
so does anyone know what I would need in the ‘???????????’ section?
I’ve tried:
[XmlAttribute("MonitorResponseRecord",AttributeName = "DisplayName")] public string DisplayName = "";
Since the attribute is
@DisplayName, that is either just:or, more explicitly:
(although a property would be preferable to a public field, IMO)
The real problem seems to be the root name; it that is the outermost part of the xml document, you will need: