Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to place DisplayName into Variable
    primarykey
    data
    text
    <p>I'm trying to do something, that may be extremely simple so please bear with me, I just want to get 'DisplayName' from an XML file into a string in my C# code. here's what I have:</p> <h3>THIS IS C#2.0 in VS2005</h3> <p>XML:</p> <pre><code>&lt;MonitorScope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="System" xmlns="http://tempuri.org/XMLSchema.xsd"&gt; &lt;PersonalSafety&gt; &lt;MonitorResponseRecord Enabled="false" DisplayName="ValveFailureAtCentralPosition"&gt; &lt;ExpressionMonitor&gt; &lt;postAlarm&gt; &lt;AlarmName&gt;Valve_Position_Fault&lt;/AlarmName&gt; &lt;Parameter1&gt; Sensor Position = {X}&lt;/Parameter1&gt; &lt;Parameter2&gt; Sensor Position = {X}&lt;/Parameter2&gt; &lt;Parameter3&gt; Sensor Position = {X}&lt;/Parameter3&gt; &lt;/postAlarm&gt; &lt;/ExpressionMonitor&gt; &lt;/MonitorResponseRecord&gt; &lt;MonitorResponseRecord ... ... ...&gt; ... ... ... ... and so on about 1600 times. </code></pre> <p>In my C# code I've attempted the following but to No Avail: C#:</p> <pre><code>public class AlarmRecord { /// &lt;remarks/&gt; public string PmAlarm; /// &lt;remarks/&gt; public string Parameter1; /// &lt;remarks/&gt; public string Parameter2; /// &lt;remarks/&gt; public string Parameter3; /// &lt;remarks/&gt; public string DisplayName; } protected void OnPostAlarm(PostAlarm postAlarm) { try { AlarmRecord alarmRecord = new AlarmRecord(); alarmRecord.PmAlarm = postAlarm.AlarmName; alarmRecord.Parameter1 = postAlarm.Parameter1; alarmRecord.Parameter2 = postAlarm.Parameter2; alarmRecord.Parameter3 = postAlarm.Parameter3; string fileName = "UMSM.009.8Root.xml"; string fullPath; fullPath = Path.GetFullPath(fileName); XmlTextReader reader = new XmlTextReader(new StringReader(fullPath)); System.Xml.XPath.XPathDocument docNav = new System.Xml.XPath.XPathDocument(reader); System.Xml.XPath.XPathNavigator Q = docNav.CreateNavigator(); System.Xml.XPath.XPathExpression EXE = Q.Compile("MonitorResponseRecord/@DisplayName"); alarmRecord.DisplayName = Convert.ToString(Q.Evaluate(EXE)); alarms.Enqueue( alarmRecord ); } catch (Exception e) { Log.Write(e); OnUnknownResponse(postAlarm); } } </code></pre> <p>basically my current issue is that durring Debug the issue that I'm noticing is in the line where 'reader' is initialized... the program usually throws an exception here</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload