当前位置: 首页>>代码示例>>C#>>正文


C# XmlReader.GetAttribute方法代码示例

本文整理汇总了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();
        }
开发者ID:Lbniese,项目名称:PawsPremium,代码行数:38,代码来源:PawsItem.cs

示例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);
 }
开发者ID:CodeMajik,项目名称:RPG,代码行数:27,代码来源:XmlParser.cs

示例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);
        }
开发者ID:OronDF343,项目名称:Sky-Jukebox,代码行数:27,代码来源:PropertyEntryMultiSerializer.cs

示例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;
                }
            }
        }
开发者ID:jstoddard,项目名称:ExamCreator,代码行数:27,代码来源:ExamQuestion.cs

示例5: MappingOption

 public MappingOption(XmlReader xml)
 {
     Schema = xml.GetAttribute("Schema");
     Prefix = xml.GetAttribute("Prefix");
     Class = xml.GetAttribute("Class");
     Pattern = xml.GetAttribute("Pattern");
 }
开发者ID:nicknystrom,项目名称:NSprocs,代码行数:7,代码来源:Options.cs

示例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;
        }
开发者ID:johann-gambolputty,项目名称:robotbastards,代码行数:42,代码来源:TypeBuilder.cs

示例7: ReadXml

 public void ReadXml(XmlReader reader)
 {
     Name = reader.GetAttribute("name");
     Super = reader.GetAttribute("super");
     Version = reader.GetAttribute("version");
     reader.ReadStartElement("class");
 }
开发者ID:kkkkyue,项目名称:FoxTool,代码行数:7,代码来源:FoxClass.cs

示例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;
        }
开发者ID:GameDevelopmentStudio,项目名称:lonely-demon-hunter,代码行数:27,代码来源:Door.cs

示例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));
            }
        }
开发者ID:mingkongbin,项目名称:anycmd,代码行数:37,代码来源:AttributeAssignmentElementReadWrite.cs

示例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;
        }
开发者ID:sgon1853,项目名称:UPM_MDD_Thesis,代码行数:38,代码来源:Error.Serializer.cs

示例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();
        }
开发者ID:downpoured,项目名称:lnzscript,代码行数:26,代码来源:DocumentationFromPythonXml.cs

示例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();
        }
开发者ID:GorelH,项目名称:schedule-metro,代码行数:33,代码来源:ScheduleClass.cs

示例13:

 void IFlickrParsable.Load(XmlReader reader)
 {
     this.FavoriteThumbnailUrl = reader.GetAttribute("thumb");
       this.FavoriteUrl = reader.GetAttribute("url");
       this.Load(reader, true);
       reader.Skip();
 }
开发者ID:rmck,项目名称:FlickrNet,代码行数:7,代码来源:FavoriteContextPhoto.cs

示例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;
                }
        }
开发者ID:MichalPrzybylski,项目名称:TSST-15Z,代码行数:31,代码来源:ConfigReader.cs

示例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);
 }
开发者ID:breslavsky,项目名称:queue,代码行数:7,代码来源:DriverElementConfig.cs


注:本文中的System.Xml.XmlReader.GetAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。