Hello,
I have an .xml file that I am using as a configuration file and I want to read the data in the file and use the values in a condition in my logic.
This is my xml file:
<?xml version="1.0" encoding="utf-8" ?>
- <caseSettings xmlns:xsi=" xmlns:xsd="- <monitorTypes>
- <monitorType>
<typeID>1</typeID>
<monitortypeid>4</monitortypeid>
<eventype>15</eventype>
<action>OOH</action>
<sla>1</sla>
<supportlevel>1</supportlevel>
<serviceitem>9</serviceitem>
<subjectcontains>is offline</subjectcontains>
<alarmstage>Second</alarmstage>
</monitorType>
- <monitorType>
<typeID>2</typeID>
<monitortypeid>1</monitortypeid>
<eventype>2</eventype>
<action>OOH</action>
<sla>3</sla>
<supportlevel>4</supportlevel>
<serviceitem>5</serviceitem>
<subjectcontains>TEST message only</subjectcontains>
<alarmstage>first</alarmstage>
</monitorType>
</monitorTypes>
</caseSettings>
This is my c sharp code that reads the xml file
XmlTextReader reader = new XmlTextReader(@"c:\kConfig.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine("VALUE = " + reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
Console.Write("</" + reader.Name);
break;
}
}
All this works fine, but this lists all the data in the xml file and I need to know when a new section starts in the xml file so I can look at the elements in that section. For example <monitorType> is the start of the new section - how do I loop through the <monitorType>, query the elements in that section for my condition and then move to the next <monitorType> section.
Is this possible and how do I do it?
Thanks in advance
I have an .xml file that I am using as a configuration file and I want to read the data in the file and use the values in a condition in my logic.
This is my xml file:
<?xml version="1.0" encoding="utf-8" ?>
- <caseSettings xmlns:xsi=" xmlns:xsd="- <monitorTypes>
- <monitorType>
<typeID>1</typeID>
<monitortypeid>4</monitortypeid>
<eventype>15</eventype>
<action>OOH</action>
<sla>1</sla>
<supportlevel>1</supportlevel>
<serviceitem>9</serviceitem>
<subjectcontains>is offline</subjectcontains>
<alarmstage>Second</alarmstage>
</monitorType>
- <monitorType>
<typeID>2</typeID>
<monitortypeid>1</monitortypeid>
<eventype>2</eventype>
<action>OOH</action>
<sla>3</sla>
<supportlevel>4</supportlevel>
<serviceitem>5</serviceitem>
<subjectcontains>TEST message only</subjectcontains>
<alarmstage>first</alarmstage>
</monitorType>
</monitorTypes>
</caseSettings>
This is my c sharp code that reads the xml file
XmlTextReader reader = new XmlTextReader(@"c:\kConfig.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine("VALUE = " + reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
Console.Write("</" + reader.Name);
break;
}
}
All this works fine, but this lists all the data in the xml file and I need to know when a new section starts in the xml file so I can look at the elements in that section. For example <monitorType> is the start of the new section - how do I loop through the <monitorType>, query the elements in that section for my condition and then move to the next <monitorType> section.
Is this possible and how do I do it?
Thanks in advance