本文整理匯總了C#中System.Xml.XmlTextReader.GetAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextReader.GetAttribute方法的具體用法?C# XmlTextReader.GetAttribute怎麽用?C# XmlTextReader.GetAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.GetAttribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: LoadTmx
public static MapLayer LoadTmx(string xmlFile)
{
XmlTextReader reader = new XmlTextReader(xmlFile);
MapLayer map = null;
while (reader.Read())
{
if (reader.Name.Equals("layer"))
{
map = new MapLayer(Int32.Parse(reader.GetAttribute("width")), Int32.Parse(reader.GetAttribute("height")));
for (int i = 0; i < map.Height; i++)
{
for (int j = 0; j < map.Width; j++)
{
while (reader.Read())
{
if (reader.Name.Equals("tile"))
break;
}
reader.MoveToContent();
map.SetTile(j, i, new Tile(Int32.Parse(reader.GetAttribute("gid")) - 1, 0));
}
}
break;
}
}
reader.Close();
return map;
}
示例2: ScanDirectory
List<SyntaxMode> ScanDirectory(string directory)
{
string[] files = Directory.GetFiles(directory);
List<SyntaxMode> modes = new List<SyntaxMode>();
foreach (string file in files) {
if (Path.GetExtension(file).Equals(".XSHD", StringComparison.OrdinalIgnoreCase)) {
XmlTextReader reader = new XmlTextReader(file);
while (reader.Read()) {
if (reader.NodeType == XmlNodeType.Element) {
switch (reader.Name) {
case "SyntaxDefinition":
string name = reader.GetAttribute("name");
string extensions = reader.GetAttribute("extensions");
modes.Add(new SyntaxMode(Path.GetFileName(file),
name,
extensions));
goto bailout;
default:
throw new HighlightingDefinitionInvalidException("Unknown root node in syntax highlighting file :" + reader.Name);
}
}
}
bailout:
reader.Close();
}
}
return modes;
}
示例3: Load
/// <summary>
/// Load matrix from XML file
/// </summary>
/// <param name="fileName">file name</param>
/// <returns>Loaded matrix</returns>
public Matrix Load(string fileName)
{
XmlTextReader textReader = new XmlTextReader(fileName);
Matrix matrix = new Matrix();
string fromWord = null;
string toWord;
float statisticValue;
while (textReader.Read())
{
if (textReader.NodeType == XmlNodeType.Element)
{
if (textReader.Name == "fromWord")
{
fromWord = textReader.GetAttribute("name");
}
else if (textReader.Name == "toWord")
{
if (fromWord != null)
{
toWord = textReader.GetAttribute("name");
float.TryParse(textReader.GetAttribute("statisticValue"), out statisticValue);
matrix.SetStatistics(fromWord, toWord, statisticValue);
}
}
}
}
textReader.Close();
return matrix;
}
示例4: LoadFromXmlFile
public void LoadFromXmlFile(string sFile)
{
Clear();
XmlTextReader xr = new XmlTextReader(sFile);
while (xr.Read())
{
if (xr.NodeType == XmlNodeType.Element)
{
if (xr.Name == "FontValidatorProject")
{
m_sComputerName = xr.GetAttribute("MachineName");
}
else if (xr.Name == "FontFile")
{
string sPath = xr.GetAttribute("Path");
m_sFilesToTest.Add(sPath);
}
else if (xr.Name == "Test")
{
string sTableName = xr.GetAttribute("Name");
string sValue = xr.GetAttribute("Value");
bool bTest = true;
if (sValue.ToLower().CompareTo("true") != 0)
{
bTest = false;
}
m_hashTestsToPerform[sTableName] = bTest;
}
}
}
xr.Close();
m_sFilename = sFile;
}
示例5: GetSyntaxModes
public static List<SyntaxMode> GetSyntaxModes(Stream xmlSyntaxModeStream)
{
XmlTextReader reader = new XmlTextReader(xmlSyntaxModeStream);
List<SyntaxMode> syntaxModes = new List<SyntaxMode>();
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
switch (reader.Name) {
case "SyntaxModes":
string version = reader.GetAttribute("version");
if (version != "1.0") {
throw new HighlightingDefinitionInvalidException("Unknown syntax mode file defininition with version " + version);
}
break;
case "Mode":
syntaxModes.Add(new SyntaxMode(reader.GetAttribute("file"),
reader.GetAttribute("name"),
reader.GetAttribute("extensions")));
break;
default:
throw new HighlightingDefinitionInvalidException("Unknown node in syntax mode file :" + reader.Name);
}
break;
}
}
reader.Close();
return syntaxModes;
}
示例6: Load
/// <summary>
/// Load one sentence from the xmltextreader.
/// </summary>
/// <param name="reader">XmlTextReader to read XML file.</param>
/// <param name="contentController">Content controller.</param>
public void Load(XmlTextReader reader, object contentController)
{
Debug.Assert(reader != null, "XmlTextReader is null");
// Get sentence id, text
this.Id = reader.GetAttribute("id");
this.Text = reader.GetAttribute("txt");
// get the phones
if (!reader.IsEmptyElement)
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "phone")
{
UnitLatticePhone phone = new UnitLatticePhone();
phone.Load(reader, contentController);
this.Phones.Add(phone);
}
else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "sentence")
{
break;
}
}
}
}
示例7: ReturnGitHubChecksumDictionary
internal static Dictionary<string, string> ReturnGitHubChecksumDictionary()
{
Dictionary<string, string> returnValues = new Dictionary<string, string>();
try
{
using (XmlTextReader reader = new XmlTextReader(GitHubProjectUrl))
{
// simply (and easily) skip the junk at the beginning
reader.MoveToContent();
//reader.ReadToDescendant("FileList");
while (reader.Read())
{
if ((reader.NodeType == XmlNodeType.Element) &&
(reader.IsStartElement()) &&
reader.HasAttributes)
{
string fileName = reader.GetAttribute(0);
string fileHash = reader.GetAttribute(1);
returnValues.Add(fileName, fileHash);
}
}
}
}
catch (Exception)
{
}
return returnValues;
}
示例8: getData
public void getData(ref SortedDictionary<string,string> data, ref List<string> localizations)
{
XmlTextReader reader = new XmlTextReader (fileName);
string currentLocal=GameConfig.Localization;
string key;
string value;
reader.Read();
while (reader.Read()) {
if (reader.Name.Equals(LOCALIZATION_NAME)) {
currentLocal = reader.GetAttribute(LOCALIZATION_ATTRIBUTE);
if (!localizations.Contains(currentLocal))
localizations.Add(currentLocal);
}
if(reader.Name.Equals(ITEM_NAME)){
key = reader.GetAttribute(ITEM_ATTRIBUTE);
value = reader.ReadElementString();
if (key!=null)
data.Add(currentLocal+key, value);
}
}
reader.Close();
reader = null;
}
示例9: checkForm
public checkForm()
{
try
{
//Microsoft.
InitializeComponent();
FileStream f = new FileStream("properties.xml", FileMode.OpenOrCreate);
XmlTextReader settings = new XmlTextReader(f);
while (settings.Read())
{
if (settings.NodeType == XmlNodeType.Element)
{
if (settings.Name.Equals("server"))
{
server = settings.GetAttribute("servername");
dbname = settings.GetAttribute("dbname");
dbuser = settings.GetAttribute("dbuser");
dbpass = settings.GetAttribute("dbpass");
dbPort = settings.GetAttribute("dbport");
}
}
}
f.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
示例10: getSettings
public void getSettings()
{
try
{
FileStream f = new FileStream("properties.xml", FileMode.OpenOrCreate);
XmlTextReader settings = new XmlTextReader(f);
while (settings.Read())
{
if (settings.NodeType == XmlNodeType.Element)
{
if (settings.Name.Equals("server"))
{
server = settings.GetAttribute("servername");
dbname = settings.GetAttribute("dbname");
dbuser = settings.GetAttribute("dbuser");
dbpass = settings.GetAttribute("dbpass");
dbPort = settings.GetAttribute("dbport");
}
}
}
f.Close();
}
catch (Exception except)
{
MessageBox.Show(except.Message);
}
}
示例11: ReadFile
public object ReadFile(string file, IProgressMonitor monitor)
{
XmlTextReader reader = new XmlTextReader (new StreamReader (file));
reader.MoveToContent ();
string version = reader.GetAttribute ("version");
if (version == null) version = reader.GetAttribute ("fileversion");
DataSerializer serializer = new DataSerializer (Runtime.ProjectService.DataContext, file);
ICombineReader combineReader = null;
if (version == "1.0" || version == "1") {
combineReader = new CombineReaderV1 (serializer, monitor);
monitor.ReportWarning (string.Format (GettextCatalog.GetString ("The file '{0}' is using an old combine file format. It will be automatically converted to the current format."), file));
}
else if (version == "2.0")
combineReader = new CombineReaderV2 (serializer, monitor);
try {
if (combineReader != null)
return combineReader.ReadCombine (reader);
else
throw new UnknownProjectVersionException (file, version);
} finally {
reader.Close ();
}
}
示例12: ScanDirectory
List<SyntaxMode> ScanDirectory(string directory)
{
string[] files = Directory.GetFiles(directory);
List<SyntaxMode> modes = new List<SyntaxMode>();
foreach (string file in files)
{
if (Path.GetExtension(file).ToUpper() == ".XSHD")
{
using (XmlTextReader reader = new XmlTextReader(file))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "SyntaxDefinition":
modes.Add(new SyntaxMode(Path.GetFileName(file),
reader.GetAttribute("name"), reader.GetAttribute("folding"), reader.GetAttribute("extensions")));
break;
default:
break; //throw new HighlightingDefinitionInvalidException("Unknown root node in syntax highlighting file :" + reader.Name);
}
}
}
}
}
}
return modes;
}
示例13: GetCollisionNode
public static ICollisionData GetCollisionNode(XmlTextReader reader, out CollisionDataType type)
{
type = CollisionDataType.None;
ICollisionData data = null;
string result = reader.GetAttribute("type");
if (result == null)
throw new FileFormatException("Nieprawid³owy opis collision data w pliku ");
switch (result)
{
case "BS":
type = CollisionDataType.CollisionSphere;
result = reader.GetAttribute("radius");
if (result == null)
throw new FileFormatException("Nieprawid³owy opis collision data w pliku ");
data = new CollisionSphere(float.Parse(result, _nfi));
break;
case "Mesh":
type = CollisionDataType.CollisionMesh;
result = reader.GetAttribute("file");
if (result == null)
throw new FileFormatException("Nieprawid³owy opis collision data w pliku ");
data = CollisionMesh.FromFile(AppConfig.MeshPath + result, false);
break;
case "Tree":
type = CollisionDataType.CollisionOctree;
result = reader.GetAttribute("file");
if (result == null)
throw new FileFormatException("Nieprawid³owy opis collision data w pliku ");
CollisionMesh m = CollisionMesh.FromFile(AppConfig.MeshPath + result, false);
data = CollisionOctree.FromMesh(m, 0, 0, 0, 20, 5, 100);
break;
}
return data;
}
示例14: ParseFromXml
public static Test ParseFromXml(string pathFile)
{
var test = new Test {PathFile = pathFile};
var xtr = new XmlTextReader(pathFile) {WhitespaceHandling = WhitespaceHandling.None};
xtr.Read(); // read the XML declaration node, advance to <test> tag
xtr.Read();
test.TestName = xtr.GetAttribute("testname");
test.Order = xtr.GetAttribute("order");
test.Questions=new List<Question>();
while (!xtr.EOF)
{
if (xtr.Name == "test" && !xtr.IsStartElement()) break;
while (xtr.Name != "question" || !xtr.IsStartElement())
xtr.Read(); // advance to <question> tag
Question question;
switch (xtr.GetAttribute("type"))
{
case "Radio":
question = QuestionWithVariants(xtr);
break;
case "Checked":
question = QuestionWithVariants(xtr);
break;
default:
throw new Exception();
}
test.Questions.Add(question);
xtr.Read();// and now either at <question> tag or </test> tag
}
xtr.Close();
test.DateDownload = DateTime.Now;
return test;
}
示例15: LoadRules
protected override void LoadRules (Category c)
{
// load xml file from smokey resources
using (Stream ruleInfo = SmokeyRunner.Smokey.GetManifestResourceStream (c.Id + ".xml")) {
using (XmlTextReader reader = new XmlTextReader (ruleInfo)) {
reader.WhitespaceHandling = WhitespaceHandling.None;
// we need to know all rule ids, names and descriptions
while (reader.Read ()) {
reader.ReadToFollowing ("Violation");
string ruleId = reader.GetAttribute ("checkID"); // id
do {
if (reader.EOF)
break;
reader.ReadToFollowing ("Translation");
} while (reader.GetAttribute ("lang") != "en");
if (reader.EOF)
break;
string ruleName = reader.GetAttribute ("typeName"); // name
reader.ReadToFollowing ("Description");
string ruleDescription = reader.ReadElementContentAsString (); // description
SmokeyRule rule = new SmokeyRule (ruleId, ruleName, ruleDescription);
SmokeyRuleCache.Add (rule);
base.AddRule (c, rule);
}
}
}
}