本文整理匯總了C#中System.Xml.XmlTextReader.ReadContentAsInt方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextReader.ReadContentAsInt方法的具體用法?C# XmlTextReader.ReadContentAsInt怎麽用?C# XmlTextReader.ReadContentAsInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.ReadContentAsInt方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetResult
/// <summary>
/// SqlServer 2005 upwards supports XML data types.
/// You could have xml text node containing data you wish converted to an int array for simpler data mapping
/// within your mapper file.
/// </summary>
/// <param name="getter"></param>
/// <returns></returns>
public object GetResult(IResultGetter getter)
{
if (getter.Value == null)
return null;
var xmlString = getter.Value.ToString();
if (String.IsNullOrEmpty(xmlString) || xmlString.Trim().Length == 0)
return null;
var integerArray = new List<int>();
using (var reader = new XmlTextReader(new StringReader(xmlString)))
{
while (reader.Read())
{
if (reader.NodeType != XmlNodeType.Text)
continue;
if (String.IsNullOrEmpty(reader.Value))
continue;
integerArray.Add(reader.ReadContentAsInt());
}
}
return integerArray.ToArray();
}
示例2: Deserialize
public void Deserialize(string str)
{
using (TextReader textReader = new StringReader(str))
using (XmlReader xmlReader = new XmlTextReader(textReader))
{
xmlReader.ReadStartElement();
xmlReader.ReadStartElement();
this.Id = new Guid(xmlReader.ReadContentAsString());
xmlReader.ReadEndElement();
xmlReader.ReadStartElement();
this.Value1 = xmlReader.ReadContentAsInt();
xmlReader.ReadEndElement();
xmlReader.ReadStartElement();
this.Value2 = xmlReader.ReadContentAsDateTime();
xmlReader.ReadEndElement();
xmlReader.ReadStartElement();
this.Value3 = xmlReader.ReadContentAsString();
xmlReader.ReadEndElement();
xmlReader.ReadStartElement();
this.Value4 = xmlReader.ReadContentAsDecimal();
xmlReader.ReadEndElement();
xmlReader.ReadEndElement();
}
}
示例3: 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;
}
示例4: Deserialize
internal void Deserialize(XmlTextReader reader)
{
bool keepreading = true;
while (keepreading)
{
reader.Read();
if (reader.Name.Equals("material") && reader.NodeType.Equals(XmlNodeType.Element))
{
VoxMaterial mat = new VoxMaterial();
mat.ID = (byte)reader.ReadContentAsInt();
mat.Name = reader.ReadContentAsString();
mat.Flags = (MatFlags)Enum.Parse(typeof(MatFlags), reader.ReadContentAsString());
mat.Density = reader.ReadContentAsFloat();
mat.Deposit = (DepositType)Enum.Parse(typeof(DepositType), reader.ReadContentAsString());
mat.Texture = UUID.Parse(reader.ReadContentAsString());
mat.Type = (MaterialType)Enum.Parse(typeof(MaterialType), reader.ReadContentAsString());
if (mat.ID > index)
{
index = mat.ID;
index++;
}
mMaterials.Add(mat.ID, mat);
mName2Byte.Add(mat.Name, mat.ID);
}
}
}
示例5: LoadFromXml
public static SystemConfig LoadFromXml(Stream stream, bool isEncrypted)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
}
using (XmlTextReader reader = new XmlTextReader(stream))
{
if (reader != null)
{
SystemConfig config = new SystemConfig();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == XmlElementConfig)
{
reader.MoveToAttribute(XmlAttribute);
string attribute = reader.ReadContentAsString();
switch (attribute)
{
case "MaxConnectionCount":
reader.MoveToAttribute(XmlValue);
config._maxConnectionCount = (ushort)reader.ReadContentAsInt();
break;
case "AdminServerListenIP":
reader.MoveToAttribute(XmlValue);
config._adminServerListenIP = reader.ReadContentAsString();
break;
case "AdminServerListenPort":
reader.MoveToAttribute(XmlValue);
config._adminServerListenPort = reader.ReadContentAsInt();
break;
case "SecondaryAdminServerListenPort":
reader.MoveToAttribute(XmlValue);
config._secondaryAdminServerListenPort = reader.ReadContentAsInt();
break;
case "AdminServerUploadFileRootPath":
reader.MoveToAttribute(XmlValue);
config._adminServerUploadFileRootPath = reader.ReadContentAsString();
if (!config._adminServerUploadFileRootPath.EndsWith(@"\")) config._adminServerUploadFileRootPath += @"\";
//若該文件夾不存在,則創建它
if (Directory.Exists(config._adminServerUploadFileRootPath) == false)
{
Directory.CreateDirectory(config._adminServerUploadFileRootPath);
}
break;
case "DbConnectionString":
{
reader.MoveToAttribute(XmlValue);
string readConnectionString = reader.ReadContentAsString();
if (isEncrypted)
{
try
{
config._dbConnectionString = CryptographyManager.TheInstance.PredefinedDecrypt(readConnectionString, Encoding.Default);
}
catch (Exception ex)
{
throw new Exception("Decrypt SystemConfig Entry \"DbConnectionString\" Failed.", ex);
}
}
else
{
config._dbConnectionString = readConnectionString;
}
}
break;
case "DefaultDbName":
reader.MoveToAttribute(XmlValue);
config._defaultDbName = reader.ReadContentAsString();
break;
case "DefaultEncoding":
reader.MoveToAttribute(XmlValue);
config._defaultEncoding = Encoding.GetEncoding(reader.ReadContentAsString());
break;
case "DefaultNewLine":
{
reader.MoveToAttribute(XmlValue);
string newLine = reader.ReadContentAsString();
if (newLine == @"\n")
{
config._defaultNewLine = "\n";
}
else if (newLine == @"\r\n")
{
config._defaultNewLine = "\r\n";
}
}
break;
case "LogDir":
reader.MoveToAttribute(XmlValue);
config._logDir = reader.ReadContentAsString();
if (!config._logDir.EndsWith(@"\")) [email protected]"\";
//若該文件夾不存在,則創建它
if (Directory.Exists(config._logDir) == false)
//.........這裏部分代碼省略.........
示例6: LoadFromFile
/// <summary>Loads the image from the given file</summary>
/// <param name="filename">The file to load from</param>
public void LoadFromFile(String filename)
{
XmlTextReader reader = null;
try
{
// Open the file
reader = new XmlTextReader(filename);
// Read to the root and determine the file version
int version = 0;
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.Element && reader.Name == "schets")
{
// Determine the version
while(reader.MoveToNextAttribute())
{
if(reader.Name == "version")
{
try
{
version = reader.ReadContentAsInt();
break;
}
catch(Exception)
{ throw new Exception("De versie lijkt in een verkeerd formaat te staan."); }
}
}
break;
}
}
if(version != 1)
throw new Exception("Foutieve bestandsversie: " + version + ".");
// Read the layers
try
{
layers.Clear();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "schets")
break;
else if (reader.NodeType == XmlNodeType.Element && reader.Name.StartsWith("layer"))
{
// Determine the layer type
Layer layer = null;
switch (reader.Name)
{
case LayerText.XML_NAME:
layer = new LayerText(new Point(0, 0), Color.Black, "");
break;
case LayerLine.XML_NAME:
layer = new LayerLine(new Point(0, 0), new Point(1, 1), 3.0f, Color.Black);
break;
case LayerRectFilled.XML_NAME:
layer = new LayerRectFilled(new Point(0, 0), new Point(1, 1), Color.Black);
break;
case LayerRectOpen.XML_NAME:
layer = new LayerRectOpen(new Point(0, 0), new Point(1, 1), 3.0f, Color.Black);
break;
case LayerEllipseFilled.XML_NAME:
layer = new LayerEllipseFilled(new Point(0, 0), new Point(1, 1), Color.Black);
break;
case LayerEllipseOpen.XML_NAME:
layer = new LayerEllipseOpen(new Point(0, 0), new Point(1, 1), 3.0f, Color.Black);
break;
case LayerPath.XML_NAME:
layer = new LayerPath(new Point(0, 0), 3.0f, Color.Black);
break;
case LayerBitmap.XML_NAME:
layer = new LayerBitmap(new Point(0, 0), new Bitmap(1,1));
break;
}
// Read the actual layer contents
if (layer != null)
{
layer.ReadFromXml(reader);
layers.Add(layer);
}
}
else throw new Exception(reader.Name);
}
}
catch(XmlException e)
{ throw new Exception(e.Message); }
catch(Exception e)
{ throw new Exception("Er is een onverwachte fout opgetreden! Foutmelding: " + e.Message); }
}
//.........這裏部分代碼省略.........
示例7: FromFile
private static void FromFile(string fileName)
{
XmlTextReader reader = new XmlTextReader(fileName);
reader.WhitespaceHandling = WhitespaceHandling.None;
try
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Paths")
{
while (!(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Paths"))
{
reader.Read();
if (reader.Name == "MeshPath")
meshPath = DefaultValues.MediaPath + reader.ReadString();
else if (reader.Name == "TexturePath")
texturePath = DefaultValues.MediaPath + reader.ReadString();
else if (reader.Name == "EffectPath")
effectPath = DefaultValues.MediaPath + reader.ReadString();
else if (reader.Name == "MapPath")
mapPath = DefaultValues.MediaPath + reader.ReadString();
else if (reader.Name == "ObjectPath")
objectPath = DefaultValues.MediaPath + reader.ReadString();
}
}
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Graphics")
{
while (!(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Graphics"))
{
reader.Read();
if (reader.Name == "Resolution")
{
reader.MoveToAttribute("width");
WindowWidth = reader.ReadContentAsInt();
reader.MoveToAttribute("height");
WindowHeight = reader.ReadContentAsInt();
}
}
}
}
}
finally
{
if (reader != null)
reader.Close();
}
}
示例8: ReadXMLProgram
//Read Program
public ProgramData ReadXMLProgram()
{
ProgramData CurrentProgram = new ProgramData();
string RootDiretory = AppDomain.CurrentDomain.BaseDirectory;
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
XmlTextReader reader = null;
switch (this.ProgramSelector)
{
case Enumerators.ProgramSelect.FTPTest:
reader = new XmlTextReader(RootDiretory + "\\Programs\\FTPTestConcentric.xml");
break;
case Enumerators.ProgramSelect.VO2MaxTest:
reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxTest.xml");
break;
default:
break;
}
while (reader.Read())
{
if (reader.ReadToFollowing("StageIndex"))
{
ProgramStage newFTPStage = new ProgramStage();
reader.Read();
newFTPStage.StageIndex = reader.ReadContentAsInt();
reader.ReadToFollowing("StageNumber");
reader.Read();
newFTPStage.StageNumber = reader.ReadContentAsInt();
reader.ReadToFollowing("StageName");
reader.Read();
newFTPStage.StageName = reader.ReadContentAsString();
reader.ReadToFollowing("StageDuration");
reader.Read();
newFTPStage.StageTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0);
reader.ReadToFollowing("Sets");
reader.Read();
while (reader.Read())
{
if (reader.Name == "Set")
{
ProgramSet newFTPSet = new ProgramSet();
reader.ReadToFollowing("SetIndex");
reader.Read();
newFTPSet.SetIndex = reader.ReadContentAsInt();
reader.ReadToFollowing("Number");
reader.Read();
newFTPSet.SetNumber = reader.ReadContentAsInt();
reader.ReadToFollowing("Duration");
reader.Read();
newFTPSet.TimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0);
reader.ReadToFollowing("Direction");
reader.Read();
newFTPSet.Direction = reader.ReadContentAsString();
reader.ReadToFollowing("DirectionFlag");
reader.Read();
int DirectionVariable = reader.ReadContentAsInt();
if (DirectionVariable == 1)
newFTPSet.SelectedDirection = Enumerators.Direction.Forward;
else if (DirectionVariable == -1)
newFTPSet.SelectedDirection = Enumerators.Direction.Backward;
reader.ReadToFollowing("Contraction");
reader.Read();
newFTPSet.Contraction = reader.ReadContentAsString();
reader.ReadToFollowing("Legs");
reader.Read();
newFTPSet.Legs = reader.ReadContentAsString();
reader.ReadToFollowing("Position");
reader.Read();
newFTPSet.Position = reader.ReadContentAsString();
reader.ReadToFollowing("RestDuration");
reader.Read();
newFTPSet.RestTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0);
reader.ReadToFollowing("Instructions");
reader.Read();
newFTPSet.Instructions = reader.ReadContentAsString();
newFTPStage.FTPSetConcentricCollection.Add(newFTPSet);
reader.Read(); //Read White Space
reader.Read(); //Read Set
reader.Read(); //Read White Space
}
else
{
break;
}
}
CurrentProgram.FTPStageCollection.Add(newFTPStage);
}
}
CurrentProgram.CurrentFTPStage = CurrentProgram.FTPStageCollection[0];
CurrentProgram.CurrentFTPStage.CurrentFTPSet = CurrentProgram.CurrentFTPStage.FTPSetConcentricCollection[0];
return CurrentProgram;
}
示例9: ReadXMLProgram
//Read Program - This method must be refactored into DataSample
private void ReadXMLProgram()
{
CurrentVO2MaxProgram = new VO2MaxProgram();
string RootDiretory = AppDomain.CurrentDomain.BaseDirectory;
XmlTextReader reader = null;
switch (DataSample.ProgramSelector)
{
case Enumerators.ProgramSelect.VO2MaxProgram1:
reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram1.xml");
lblTitle.Text = "Program: VO2 Max Program 1";
lblDescription.Text = "Program Time: 30 min";
CurrentPowerIndex = GlobalVariables.VO2MaxProgram1PB;
break;
case Enumerators.ProgramSelect.VO2MaxProgram2:
reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram2.xml");
lblTitle.Text = "Program: VO2 Max Program 2";
lblDescription.Text = "Program Time: 30 min";
CurrentPowerIndex = GlobalVariables.VO2MaxProgram2PB;
break;
case Enumerators.ProgramSelect.VO2MaxProgram3:
reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram3.xml");
lblTitle.Text = "Program: VO2 Max Program 3";
lblDescription.Text = "Program Time: 26 min";
CurrentPowerIndex = GlobalVariables.VO2MaxProgram3PB;
break;
case Enumerators.ProgramSelect.VO2MaxProgram4:
reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram4.xml");
lblTitle.Text = "Program: VO2 Max Program 4";
lblDescription.Text = "Program Time: 20 min";
CurrentPowerIndex = GlobalVariables.VO2MaxProgram4PB;
break;
case Enumerators.ProgramSelect.CPM:
reader = new XmlTextReader(RootDiretory + "\\Programs\\CPMProgram.xml");
lblTitle.Text = "Program: Continuous Passive Motion (CPM)";
lblDescription.Text = "Program Time: 20 min";
CurrentPowerIndex = GlobalVariables.CPMProgramPB;
break;
case Enumerators.ProgramSelect.Proprioception:
reader = new XmlTextReader(RootDiretory + "\\Programs\\ProprioceptionProgram.xml");
lblTitle.Text = "Program: Proprioception";
lblDescription.Text = "Program Time: 10 min";
CurrentPowerIndex = GlobalVariables.PropriocenptionProgramPB;
break;
case Enumerators.ProgramSelect.RehabBilateral:
reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabBilateral.xml");
lblTitle.Text = "Program: Rehabilitation - Bilateral (9 Stages)";
lblDescription.Text = "Program Time: 15 min";
CurrentPowerIndex = GlobalVariables.RehabProgramPB;
break;
case Enumerators.ProgramSelect.RehabLeftLeg:
reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabLeftLeg.xml");
lblTitle.Text = "Program: Rehabilitation - Left Leg (11 Stages)";
lblDescription.Text = "Program Time: 15 min";
CurrentPowerIndex = GlobalVariables.RehabProgramLeftPB;
break;
case Enumerators.ProgramSelect.RehabRightLeg:
reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabRightLeg.xml");
lblTitle.Text = "Program: Rehabilitation - Right Leg (11 Stages)";
lblDescription.Text = "Program Time: 15 min";
CurrentPowerIndex = GlobalVariables.RehabProgramRightPB;
break;
//case Enumerators.ProgramSelect.CustomProgram:
// reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabBilateral.xml");
// lblTitle.Text = "Program: Rehabilitation - Bilateral (9 Stages)";
// lblDescription.Text = "Program Time: 15 min";
// CurrentPowerIndex = GlobalVariables.RehabProgramPB;
// break;
default:
break;
}
while (reader.Read())
{
if (reader.ReadToFollowing("StageIndex"))
{
VO2MaxStage newVO2MaxStage = new VO2MaxStage();
reader.Read();
newVO2MaxStage.StageIndex = reader.ReadContentAsInt();
reader.ReadToFollowing("StageNumber");
reader.Read();
newVO2MaxStage.StageNumber = reader.ReadContentAsInt();
reader.ReadToFollowing("StageName");
reader.Read();
newVO2MaxStage.StageName = reader.ReadContentAsString();
reader.ReadToFollowing("StageDuration");
reader.Read();
newVO2MaxStage.StageTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0);
reader.ReadToFollowing("Sets");
reader.Read();
while (reader.Read())
{
if (reader.Name == "Set")
{
VO2MaxSet newVO2MaxSet = new VO2MaxSet();
reader.ReadToFollowing("SetIndex");
reader.Read();
newVO2MaxSet.SetIndex = reader.ReadContentAsInt();
//.........這裏部分代碼省略.........