本文整理汇总了C#中System.Xml.XmlReader.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.GetAttribute方法的具体用法?C# XmlReader.GetAttribute怎么用?C# XmlReader.GetAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlReader
的用法示例。
在下文中一共展示了XmlReader.GetAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadXml
/// <summary>
/// Since our conditions implement a behavior (interface) and not a state (base class), serialization must be done
/// manually.
/// </summary>
public void ReadXml(XmlReader reader)
{
var name = reader.GetAttribute("Name");
var entry = reader.GetAttribute("Entry");
var myState = reader.GetAttribute("MyState");
var enabled = reader.GetAttribute("Enabled");
reader.Read();
Name = name;
int outEntry;
if (!int.TryParse(entry, out outEntry))
{
Log.Gui(
string.Format(
"WARNING: Unable to load item \"{0}\" because the entry id is missing. This is due to having an older version of the Paws-Items.xml settings file. Please either delete the Paws-Items.xml file under your settings folder, or re-add items using the Items tab in the Paws user interface.",
name));
return;
}
Entry = outEntry;
MyState outMyState;
Enum.TryParse(myState, out outMyState);
MyState = outMyState;
Enabled = bool.Parse(enabled);
var serializer = new XmlSerializer(Conditions.GetType());
Conditions = (List<ItemCondition>) serializer.Deserialize(reader);
reader.ReadEndElement();
}
示例2: createPlayer
void createPlayer(XmlReader reader)
{
Vector2 pos = Vector2.Zero;
TextureMap t = new TextureMap();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "position":
{
reader.ReadToDescendant("x");
float x = (float)float.Parse((reader.GetAttribute(0)));
reader.ReadToNextSibling("y");
float y = (float)float.Parse((reader.GetAttribute(0)));
pos = new Vector2(x, y);
}
break;
default:
int o = 0;//fer teh deboog
break;
}
}
}
Player p = new Player(pos, t);
}
示例3: ReadXml
public static KeyValuePair<string, Property> ReadXml(XmlReader reader)
{
var key = reader.GetAttribute("Key");
var type = reader.GetAttribute("Type");
reader.MoveToElement();
reader.ReadStartElement("PropertyEntry");
Property value = null;
try
{
var t = Type.GetType(type);
value = (Property)GetSerializer(t).Deserialize(reader);
}
catch (Exception ex)
{
Console.WriteLine("Deserialization failed: " + ex.Message);
Console.WriteLine("Property Key: " + key);
Console.WriteLine("Property Type Qualified Name: " + type);
Console.WriteLine("Stacktrace: " + ex.StackTrace);
}
reader.ReadEndElement();
reader.MoveToContent();
if (value == null)
throw new Exception();
return new KeyValuePair<string, Property>(key, value);
}
示例4: ExamQuestion
public ExamQuestion(XmlReader reader)
: this()
{
QuestionIdentifier = reader.GetAttribute("identifier");
Question = reader.GetAttribute("question");
Image = reader.GetAttribute("image");
while (!reader.EOF)
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.Name == "Answer")
Answer = reader.ReadElementContentAsString();
else if (reader.Name == "Distractor")
Distractors.Add(reader.ReadElementContentAsString());
else
reader.Read();
break;
case XmlNodeType.EndElement:
return;
default:
reader.Read();
break;
}
}
}
示例5: MappingOption
public MappingOption(XmlReader xml)
{
Schema = xml.GetAttribute("Schema");
Prefix = xml.GetAttribute("Prefix");
Class = xml.GetAttribute("Class");
Pattern = xml.GetAttribute("Pattern");
}
示例6: TypeBuilder
/// <summary>
/// Setup constructor
/// </summary>
/// <param name="parameters">Load parameters</param>
/// <param name="errors">Error collection</param>
/// <param name="reader">XML reader positioned at the element that created this builder</param>
/// <param name="parentBuilder">Parent builder</param>
public TypeBuilder( ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader, BaseBuilder parentBuilder )
: base(parameters, errors, reader, parentBuilder)
{
// Retrieve type name and optional assembly name from the element
string typeName = reader.GetAttribute( "value" );
string assemblyName = reader.GetAttribute( "assembly" );
if ( typeName == null )
{
throw new ApplicationException( string.Format( "Element \"{0}\" requires a \"type\" attribute", reader.Name ) );
}
Type objectType = null;
if ( assemblyName == null )
{
// Get the object type from the currently loaded set of assemblies
objectType = AppDomainUtils.FindType( typeName );
if ( objectType == null )
{
throw new ApplicationException( string.Format( "Failed to find type \"{0}\" in app domain" , typeName ) );
}
}
else
{
// Get the object type from the specified assembly
Assembly assembly = AppDomain.CurrentDomain.Load( assemblyName );
objectType = assembly.GetType( typeName );
if ( objectType == null )
{
throw new ApplicationException( string.Format( "Failed to find type \"{0}\" in assembly \"{1}\"", typeName, assemblyName ) );
}
}
BuildObject = objectType;
}
示例7: ReadXml
public void ReadXml(XmlReader reader)
{
Name = reader.GetAttribute("name");
Super = reader.GetAttribute("super");
Version = reader.GetAttribute("version");
reader.ReadStartElement("class");
}
示例8: parseFromFile
public static bool parseFromFile(Door entity, XmlReader reader)
{
// Fill info into provided entity
int x, y;
string orientation;
try
{
x = int.Parse(reader.GetAttribute("x"));
y = int.Parse(reader.GetAttribute("y"));
orientation = reader.GetAttribute("orientation");
}
catch (Exception err)
{
Console.WriteLine(err.Message);
return false;
}
entity.x = x;
entity.y = y;
if (orientation == "Front")
entity.orientation = Orientation.Front;
else
entity.orientation = Orientation.Side;
return true;
}
示例9: AttributeAssignmentElementReadWrite
/// <summary>
/// Creates an instance of the ReadWriteAttributeAssignment using the provided XmlReader.
/// </summary>
/// <param name="reader">The XmlReader positioned at the AttributeAssignament node.</param>
/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
public AttributeAssignmentElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
: base(XacmlSchema.Policy, schemaVersion)
{
if (reader == null) throw new ArgumentNullException("reader");
if (reader.LocalName == Consts.Schema1.ObligationElement.AttributeAssignment &&
ValidateSchema(reader, schemaVersion))
{
if (reader.HasAttributes)
{
// Load all the attributes
while (reader.MoveToNextAttribute())
{
if (reader.LocalName == Consts.Schema1.AttributeValueElement.DataType)
{
_dataType = reader.GetAttribute(Consts.Schema1.AttributeValueElement.DataType);
}
else if (reader.LocalName == Consts.Schema1.AttributeAssignmentElement.AttributeId)
{
_attributeId = reader.GetAttribute(Consts.Schema1.AttributeAssignmentElement.AttributeId);
}
}
reader.MoveToElement();
}
// Load the node contents
_contents = reader.ReadInnerXml();
}
else
{
throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
}
}
示例10: Deserialize
/// <summary>
/// Obtains the type and value of a parameter from an XML Error file.
/// </summary>
/// <param name="reader">XML Error file.</param>
/// <param name="parameter">Parameter to obtain.</param>
/// <returns>Parameter.</returns>
public static Parameter Deserialize(XmlReader reader, Parameter parameter)
{
if (reader.IsStartElement(DTD.Error.ErrorParams.TagErrorParam))
{
if (parameter == null)
{
parameter = new Parameter();
}
// Read Attributes of Node.
parameter.Key = reader.GetAttribute(DTD.Error.ErrorParams.TagKey);
switch (reader.GetAttribute(DTD.Error.ErrorParams.TagType))
{
case ResponseException.ErrorKey:
parameter.Type = ErrorParamType.Key;
break;
case ResponseException.ErrorLiteral:
parameter.Type = ErrorParamType.Literal;
break;
}
if (!reader.IsEmptyElement)
{
parameter.Text = reader.ReadString();
}
else
{
reader.Skip();
}
}
return parameter;
}
示例11: expandNamespace_function
private void expandNamespace_function(TreeNodeCollection outNodes, string strSection, string strNamespace, XmlReader reader)
{
bool bContinue = reader.ReadToDescendant("function");
while (bContinue)
{
NodeDocPythonFunction node = newnode(strSection, strNamespace, reader.GetAttribute("name"));
outNodes.Add(node);
bool bInstance = reader.GetAttribute("instance") == "true";
node.bIsInstanceMethod = bInstance;
string strSyntax = reader.GetAttribute("fullsyntax"); if (strSyntax != null && strSyntax != "") node.strFullSyntax = strSyntax;
node.strDocumentation = getFunctionDocAndExample(reader.ReadSubtree()); //assumes doc before example
if (this.emphasizeStaticness())
{
if (!bInstance)
{
//change visible node text to emphasize static-ness
node.Text = node.strNamespacename + "." + node.strFunctionname;
}
}
bContinue = ReadToNextSibling(reader, "function");
}
reader.Close();
}
示例12: ReadFromXml
public void ReadFromXml(XmlReader reader)
{
reader.MoveToContent();
type = reader.GetAttribute("type");
code = reader.GetAttribute("code");
location = reader.GetAttribute("location");
string time = reader.GetAttribute("time");
if (time.Length == 5)
{
hours = int.Parse(time.Substring(0, 2));
minutes = int.Parse(time.Substring(3, 2));
}
else if (time.Length == 4)
{
hours = int.Parse(time.Substring(0, 1));
minutes = int.Parse(time.Substring(2, 2));
}
string weekStr;
if ((weekStr = reader.GetAttribute("week")) != null)
week = int.Parse(weekStr);
else
week = 0;
if ((group = reader.GetAttribute("group")) == null)
group = "";
reader.Skip();
}
示例13:
void IFlickrParsable.Load(XmlReader reader)
{
this.FavoriteThumbnailUrl = reader.GetAttribute("thumb");
this.FavoriteUrl = reader.GetAttribute("url");
this.Load(reader, true);
reader.Skip();
}
示例14: readCommandsFromConfig
public static Dictionary<int, string> readCommandsFromConfig(string configurationFileName)
{
Dictionary<int, string> portCommandDictionary = new Dictionary<int, string>();
string defaultDirectoryPath = Directory.GetCurrentDirectory();
DirectoryInfo di = new DirectoryInfo((((new DirectoryInfo(defaultDirectoryPath).Parent).Parent).Parent).FullName + "\\Configs");
configurationFilePath = setupDirectoryPath(di.ToString(), configurationFileName);
using (
configReader = XmlReader.Create(configurationFilePath))
try
{
while (configReader.Read())
{
if ((configReader.NodeType == XmlNodeType.Element) && (configReader.Name == "port"))
{
if (configReader.HasAttributes)
{
portCommandDictionary.Add(int.Parse(configReader.GetAttribute("value")), configReader.GetAttribute("command"));
}
}
}
return portCommandDictionary;
}
catch
(Exception e)
{
return null;
}
}
示例15: DeserializeElement
protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
{
string assembly = reader.GetAttribute("assembly");
string settings = reader.GetAttribute("settings");
config = Activator.CreateInstance(Assembly.Load(assembly).GetType(settings)) as DriverConfig;
config.ConfigDeserializeElement(reader, serializeCollectionKey);
}