Consol program i form program
HejJeg har lavet denne consol app i C#:
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load( @"C:\S2.xml" );
foreach( XmlElement LogEvent in xmlDocument.SelectNodes( @"Events/LogEvent" ) )
{
string actionString = LogEvent.GetAttribute("Value");
int actionInt = Convert.ToInt16(actionString);
char c = (char)actionInt;
Console.WriteLine("----------------------------------------------------------");
Console.WriteLine("The ASCII value: " + actionInt + " " + "Converted to text: " + c);
Console.WriteLine("Action taken: {0} At this time: {1}.", LogEvent.GetAttribute("Action"), LogEvent.GetAttribute("Time"));
Console.WriteLine("----------------------------------------------------------");
}
}
}
Som tager nogen data fra en xml fil og printer nogle forskellige attributter ud.
Men jeg vil gerne have det ind i mit Form program (også C#) - hvor jeg vil have den metode jeg har lavet til at køre når jeg trykker på en button og så skal den skrive det ud i et tekstfelt istedet for i en consol?
Hvordan gør jeg dette?
- sidespørgsmål:
Jeg har en xml fil der ser således ud:
<?xml version="1.0" encoding="utf-8"?>
<Logfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="Translog">
<VersionString>3.2.5.0</VersionString>
<Subject />
<startTime>2008-03-11T09:13:01.644</startTime>
<endTime>2008-03-11T09:16:37.773</endTime>
<Project>
<FileName>C:\Program Files\Translog 2006\Projects\FKK Text B.project</FileName>
<Description />
<sourceText>
<Text>{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}}
\viewkind4\uc1\pard\lang2057\f0\fs41 On a more positive note, what the report also makes clear is that speedy and concerted international action can still avoid some of the most catastrophic projections. What is needed is a political response to what the scientists are telling us is necessary. Politically, the lights are on green for a breakthrough in the form of a roadmap for a new international agreement on enhanced global action to fight climate change in the period after 2012, the year the first commitment period of the Kyoto Protocol expires. The Bali conference will not deliver a fully negotiated and agreed climate deal, but is definitely aimed at setting the necessary wheels in motion.\lang1033\fs17\par
}
</Text>
<UnitMarkers />
<Dictionary />
</sourceText>
<versionString />
<targetFont>Tahoma</targetFont>
<lineHeightSource>1</lineHeightSource>
<lineHeightTarget>1.5</lineHeightTarget>
<backgroundColorSource />
<backgroundColorTarget />
<textColorTarget />
<textAlignmentTarget>Left</textAlignmentTarget>
<targetFontSize>20</targetFontSize>
<useSourceText>true</useSourceText>
<viewNextUnitKey>0</viewNextUnitKey>
<promptSubjectName>false</promptSubjectName>
<syncEnabled>false</syncEnabled>
<broadcastEnabled>true</broadcastEnabled>
<udpIP />
<udpPort>18193</udpPort>
<signalInterval>10</signalInterval>
<audioEnabled>false</audioEnabled>
<eyeTrackerEnabled>true</eyeTrackerEnabled>
<useDictionaryPrompts>false</useDictionaryPrompts>
<useExtendedTranslations>false</useExtendedTranslations>
</Project>
<Events>
<LogEvent Action="5" Value="1" Cursor="0" Block="0" Time="00:00:00:000" />
<LogEvent Action="7" Value="1" Cursor="141" Block="12" Time="00:00:01:342" />
<LogEvent Action="7" Value="1" Cursor="154" Block="11" Time="00:00:01:836" />
<LogEvent Action="7" Value="1" Cursor="118" Block="5" Time="00:00:02:625" />
<LogEvent Action="7" Value="1" Cursor="124" Block="4" Time="00:00:03:604" />
og så fortsætter eventsne:
Mit consol program virker kun hvis jeg fjerner alt andet i xml filen end de <events> som den skal læse ud fra - skal jeg definere hvor i xml-filen min xmlreader skal starte eller hvordan klarer jeg dette problem?