本文整理匯總了C#中System.Xml.XmlTextReader.ReadString方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextReader.ReadString方法的具體用法?C# XmlTextReader.ReadString怎麽用?C# XmlTextReader.ReadString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.ReadString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: HoTro
public HoTro()
{
try
{
string TepCauHinh = Application.StartupPath + "\\cauhinh.xml";
XmlTextReader rd = new XmlTextReader(TepCauHinh);
while (rd.Read())
if (rd.NodeType == XmlNodeType.Element)
{
if (rd.LocalName.Equals("TenMayChu"))
TenMayChu = rd.ReadString();
if (rd.LocalName.Equals("TenCoSoDuLieu"))
TenCoSoDuLieu = rd.ReadString();
if (rd.LocalName.Equals("TenDangNhap"))
TenDangNhap = rd.ReadString();
if (rd.LocalName.Equals("MatKhau"))
MatKhau = rd.ReadString();
}
if (rd != null) rd.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例2: SettingsRead
public string SettingsRead(string name)
{
XmlTextReader xmlRead = new XmlTextReader(AppDomain.CurrentDomain.BaseDirectory + "\\inc\\settings.xml");
try
{
while (xmlRead.Read())
{
if (xmlRead.NodeType == XmlNodeType.Element)
{
switch (xmlRead.Name)
{
case "server":
server = xmlRead.ReadString();
break;
case "cache":
cache = xmlRead.ReadString();
break;
}
}
}
xmlRead.Close();
}
catch (Exception ex)
{
Console.WriteLine("XML Error: " + ex.Message);
}
if (name == "server") return server;
else return cache;
}
示例3: getVars
public static void getVars()
{
//System.Web.HttpContext.Current.Server.MapPath("../Persist/DATASOURCE.xml");
XmlTextReader reader = new XmlTextReader(System.Web.HttpContext.Current.Server.MapPath("../Persist/DATASOURCE.xml"));
reader.Read();
while (reader.Read())
{
if (reader.Name == "Server")
{
server = reader.ReadString();
}
if (reader.Name == "Database")
{
Database = reader.ReadString();
}
if (reader.Name == "User")
{
User = reader.ReadString();
}
if (reader.Name == "Password")
{
Password = reader.ReadString();
}
}
}
示例4: LoadConfig
internal static void LoadConfig(this DatabaseConfig config)
{
CheckForConfigFile();
using (var xmlReader = new XmlTextReader(FilePath))
{
while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element)
{
switch (xmlReader.Name)
{
case "ConnectionString":
config.ConnectionString = xmlReader.ReadString();
break;
case "DatabaseEngine":
xmlReader.MoveToContent();
ServiceLocator.DatabaseEngine value;
Enum.TryParse(xmlReader.ReadString(), out value);
config.DatabaseEngine = value;
break;
}
}
}
}
}
示例5: ReadSensorData
public static SensorData ReadSensorData(string soap) {
SensorData sd;
XmlTextReader xmread;
sd = null;
try {
sd = new SensorData();
using (System.IO.StringReader read = new System.IO.StringReader(soap)) {
xmread = new XmlTextReader(read);
xmread.ReadStartElement("SensorDataContainer");
xmread.ReadStartElement("Sensor");
xmread.ReadStartElement("HasMotion");
sd.HasMotion = bool.Parse(xmread.ReadString());
xmread.ReadEndElement();
xmread.ReadStartElement("NodeId");
sd.NodeId = int.Parse(xmread.ReadString());
xmread.ReadEndElement();
xmread.ReadStartElement("PowerLevel");
sd.PowerLevel = int.Parse(xmread.ReadString());
xmread.ReadEndElement();
xmread.ReadStartElement("TimeStamp");
sd.TimeStamp = DateTime.Parse(xmread.ReadString());
xmread.ReadEndElement();
xmread.ReadEndElement();
xmread.ReadEndElement();
}
} catch (Exception) {
throw;
}
return (sd);
}
示例6: TriviaServer
public TriviaServer(int port)
{
IPAddress ipAddress = Dns.Resolve(Dns.GetHostName()).AddressList[0];
this.port = port;
this.connector = new TCPIPconnectorServer(port, ipAddress);
this.dbConnected = true;
string login = "";
string password = "";
string dbName = "";
XmlTextReader reader;
try
{
reader = new XmlTextReader("config.xml");
while (reader.Read())
{
if (reader.IsStartElement())
{
if (reader.Name == "login")
{
login = reader.ReadString();
}
if (reader.Name == "password")
{
password = reader.ReadString();
}
if (reader.Name == "dbName")
{
dbName = reader.ReadString();
}
}
}
reader.Close();
}
catch (Exception e)
{
Logging.LogEvent("Constructor|XmlTextReader", e.Message);
}
try
{
this.DBConnector = new DatabaseConnector("localhost", login, password, dbName);
TriviaServer.answerID = this.DBConnector.GetNumberOfUserAnswer() + 1;
}
catch (Exception e)
{
Logging.LogEvent("Constructor|DatabaseConnector", e.Message + " " + login + " " + password + " " + dbName);
this.dbConnected = false;
}
this.userList = new List<User>();
this.userThread = new List<Thread>();
this.mutex = new ManualResetEvent(true);
}
示例7: readXML
public DataTable readXML(string qID, string xmlPath)
{
DataTable dt = new DataTable();
string quest = "";
string part = "";
dt.Columns.Add("name");
dt.Columns.Add("id");
try
{
XmlTextReader reader = new XmlTextReader(xmlPath);
while (reader.Read())
{
switch (reader.Name)
{
case "question":
if (reader.AttributeCount > 0 && qID.ToUpper() == reader.GetAttribute("value").ToUpper())//OM DETR FINN
{
part = reader.GetAttribute("part").ToUpper();
}
else
{
reader.Skip();
}
break;
case "txt":
quest = reader.ReadString(); //Frågan sparas till en string behöver ha en tupple
break;
case "qone":
dt.Rows.Add();//Nedan är svarsalternativen
dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();
break;
case "qtwo":
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();
break;
case "qthree":
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();
break;
case "qfour":
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();
break;
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
return null;
}
return dt;
}
示例8: Read
/// <summary>
/// Read the specified xml and uri.
/// </summary>
/// <description>XML is the raw Note XML for each note in the system.</description>
/// <description>uri is in the format of //tomboy:NoteHash</description>
/// <param name='xml'>
/// Xml.
/// </param>
/// <param name='uri'>
/// URI.
/// </param>
public static Note Read(XmlTextReader xml, string uri)
{
Note note = new Note (uri);
DateTime date;
int num;
string version = String.Empty;
while (xml.Read ()) {
switch (xml.NodeType) {
case XmlNodeType.Element:
switch (xml.Name) {
case "note":
version = xml.GetAttribute ("version");
break;
case "title":
note.Title = xml.ReadString ();
break;
case "text":
// <text> is just a wrapper around <note-content>
// NOTE: Use .text here to avoid triggering a save.
note.Text = xml.ReadInnerXml ();
break;
case "last-change-date":
if (DateTime.TryParse (xml.ReadString (), out date))
note.ChangeDate = date;
else
note.ChangeDate = DateTime.Now;
break;
case "last-metadata-change-date":
if (DateTime.TryParse (xml.ReadString (), out date))
note.MetadataChangeDate = date;
else
note.MetadataChangeDate = DateTime.Now;
break;
case "create-date":
if (DateTime.TryParse (xml.ReadString (), out date))
note.CreateDate = date;
else
note.CreateDate = DateTime.Now;
break;
case "x":
if (int.TryParse (xml.ReadString (), out num))
note.X = num;
break;
case "y":
if (int.TryParse (xml.ReadString (), out num))
note.Y = num;
break;
}
break;
}
}
return note;
}
示例9: GetXMLSettings
public static void GetXMLSettings()
{
string xmlfile = @"settings.xml";
int xmlfound = 0;
try
{
XmlTextReader reader = new XmlTextReader(AppDomain.CurrentDomain.BaseDirectory + @"\\" + xmlfile);
while (reader.Read())
{
string n = reader.Name;
xmlfound = 1;
switch (n)
{
// logtofile should be the first to be read from the xml
// because if it is !=1 we should not log to file
case "logtofile":
tools.logtofile = reader.ReadString();
WriteErrorLog("logtofile ok");
break;
// logtoeventviewer should be second to load
case "logtoeventviewer":
tools.logtoEV = reader.ReadString();
WriteErrorLog("logtoEV ok");
break;
case "hash":
tools.hash = reader.ReadString();
WriteErrorLog("hash ok");
break;
case "updateinterval":
tools.updateinterval = Convert.ToInt32(reader.ReadString());
WriteErrorLog("updateinterval ok");
break;
case "serverurl":
tools.serverurl = reader.ReadString();
WriteErrorLog("serverurl ok");
break;
case "publicip":
tools.publicip = reader.ReadString();
WriteErrorLog("publicip ok");
break;
}
}
}
catch (Exception exp)
{
tools.hash = "";
WriteErrorLog("XML: " + exp.Message);
}
if (0 == xmlfound)
{
System.Diagnostics.EventLog.WriteEntry("DecimalDNSService", "ERROR! hash not found.", EventLogEntryType.Error, 19289);
WriteErrorLog("Error in settings.xml.");
}
}
示例10: ChestBonusInfo
/// <summary>
/// Loads the chest bonus descriptions from the given XML
/// file and sets up the internal structures.
/// </summary>
static ChestBonusInfo()
{
try
{
// Get the manifest string
Stream stream = typeof(ChestBonusInfo).Assembly
.GetManifestResourceStream("CuteGod.bonuses.xml");
// Create an XML reader out of it
XmlTextReader xml = new XmlTextReader(stream);
ChestBonusInfo sp = null;
ChestBonusType type = ChestBonusType.Maximum;
// Loop through the file
while (xml.Read())
{
// See if we finished a node
if (xml.NodeType == XmlNodeType.EndElement &&
xml.LocalName == "bonus")
{
hash[type] = sp;
sp = null;
}
// Ignore all but start elements
if (xml.NodeType != XmlNodeType.Element)
continue;
// Check for name
if (xml.LocalName == "bonus")
{
sp = new ChestBonusInfo();
type = (ChestBonusType) Enum
.Parse(typeof(ChestBonusType), xml["type"]);
sp.type = type;
}
else if (xml.LocalName == "title")
sp.Title = xml.ReadString();
else if (xml.LocalName == "block")
sp.BlockKey = xml.ReadString();
else if (xml.LocalName == "description")
sp.Description = xml.ReadString();
}
}
catch (Exception e)
{
Logger.Error(typeof(ChestBonusInfo),
"Cannot load penalties: {0}", e.Message);
throw e;
}
}
示例11: LoadData
public void LoadData(String filename)
{
if (File.Exists(filename))
{
XmlTextReader reader = new XmlTextReader(filename);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
{
switch (reader.Name)
{
case "TrackerAddress":
{
this.TrackerAddress = reader.ReadString();
break;
}
case "MaxTimeout":
{
this.MaxTimeout = Int32.Parse(reader.ReadString());
break;
}
case "Port":
{
this.Port = Int32.Parse(reader.ReadString());
break;
}
case "ListenPort":
{
this.ListenPort = Int32.Parse(reader.ReadString());
break;
}
}
break;
}
}
}
reader.Close();
}
else
{
// default this
this.TrackerAddress = "127.0.0.1";
this.MaxTimeout = 30000;
this.Port = 9351;
this.ListenPort = 9757;
this.SaveData(filename);
}
}
示例12: LoadRules
public static NamingRules LoadRules(string xmlPath)
{
NamingRules namingRules = new NamingRules();
namingRules.rules = new List<NamingRule>();
using (XmlReader reader = new XmlTextReader(xmlPath))
{
reader.ReadStartElement("Rules");
reader.ReadStartElement("GeneralSettings");
reader.ReadStartElement("FilenameRegex");
namingRules.filenameRegex = reader.ReadString();
reader.ReadEndElement();
reader.ReadStartElement("ContextDepth");
namingRules.contextDepth = reader.ReadContentAsInt();
if (namingRules.ContextDepth < 1 || namingRules.ContextDepth > 4)
throw new FormatException("Context Depth must be between 1 and 4");
reader.ReadEndElement();
reader.ReadStartElement("ContextSeparator");
namingRules.contextSeparator = reader.ReadString();
reader.ReadEndElement();
reader.ReadEndElement();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.EndElement)
{
System.Diagnostics.Debug.Assert(reader.Name == "Rules");
break;
}
//if (reader.IsStartElement())
// System.Diagnostics.Debug.Assert(reader.Name == "Rule");
reader.ReadStartElement("Rule");
//reader.Read();
reader.ReadStartElement("SearchString");
string regex = reader.ReadString();
reader.ReadEndElement();
reader.ReadStartElement("Replacement");
string replacement = reader.ReadString();
reader.ReadEndElement();
reader.ReadEndElement();
namingRules.rules.Add(new NamingRule(regex, replacement));
}
reader.ReadEndElement();
}
return namingRules;
}
示例13: load
/// <summary>
/// Loads all the settings from the XML file "settings.xml" which is in the same directory as the executable.
/// </summary>
public static void load()
{
if (File.Exists("settings.xml"))
{
string text = File.ReadAllText("settings.xml");
XMLChecker checker = new XMLChecker();
if (checker.checkSafe(text)) //If we're good to go
{
XmlTextReader reader = new XmlTextReader(new StringReader(text));
while (reader.Read()) //Parse the settings
{
if (reader.Name == "notifications") //Gets the value for notify
{
bool result;
if (Boolean.TryParse(reader.ReadString(), out result))
{
notify = result;
}
else //It isn't a boolean so we just default it, but let the user know
{
MessageBox.Show("Notification value is non-boolean, defaulted to true.", "Error", MessageBoxButtons.OK);
notify = true;
}
}
if (reader.Name == "server") //Set the server
{
server = reader.ReadString();
}
}
}
else //XML was bad, delete the file and try again (so we have a clean file)
{
File.Delete("settings.xml");
Setting.load();
}
}
else //No settings found, create a default file that is on the localhost for a server
{
server = "http://localhost/ticketSystem/webshield.php";
notify = true;
Setting.save(); //Create a default settings file
}
}
示例14: ExtractBooleanValue
public bool ExtractBooleanValue(XmlTextReader reader)
{
bool result;
if (ExtractBoolFromOffOnString(reader.ReadString(), out result))
{
return result;
}
if (!Boolean.TryParse(reader.ReadString(), out result))
{
return false;
}
return result;
}
示例15: CheckNewVersionAvailable
public static bool CheckNewVersionAvailable()
{
string versionString = "0.5";
bool newVersion = false;
string versionFile = "http://www.worxpace.de/uih/version.xml";
WebRequest requestVersionFile = WebRequest.Create(versionFile);
WebResponse responseVersionFile = requestVersionFile.GetResponse();
StreamReader xmlInputStream = new StreamReader(responseVersionFile.GetResponseStream());
XmlTextReader xmlReader = new XmlTextReader(xmlInputStream);
while (xmlReader.Read())
{
switch (xmlReader.Name)
{
case "fileVersion":
Version actualVersion = new Version(versionString);
Version currentVersion = new Version(xmlReader.ReadString());
if (currentVersion <= actualVersion)
{
newVersion = false;
}
else
{
newVersion = true;
}
break;
}
}
return newVersion;
}