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


C# XElement.Element方法代码示例

本文整理汇总了C#中System.Xml.Linq.XElement.Element方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.Element方法的具体用法?C# XElement.Element怎么用?C# XElement.Element使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.Element方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FromXml

        public static MusicInfo FromXml(XElement musicNode, string basePath)
        {
            MusicInfo music = new MusicInfo();

            var introNode = musicNode.Element("Intro");
            var loopNode = musicNode.Element("Loop");

            XAttribute trackAttr = musicNode.Attribute("nsftrack");

            if (introNode != null || loopNode != null)
            {
                music.Type = AudioType.Wav;
                if (introNode != null) music.IntroPath = FilePath.FromRelative(introNode.Value, basePath);
                if (loopNode != null) music.LoopPath = FilePath.FromRelative(loopNode.Value, basePath);
            }
            else if (trackAttr != null)
            {
                music.Type = AudioType.NSF;

                int track;
                if (!trackAttr.Value.TryParse(out track) || track <= 0) throw new GameXmlException(trackAttr, "Sound track attribute must be an integer greater than zero.");
                music.NsfTrack = track;
            }
            else
            {
                music.Type = AudioType.Unknown;
            }

            return music;
        }
开发者ID:Tesserex,项目名称:CME-Common-Library,代码行数:30,代码来源:MusicInfo.cs

示例2: Addr3

 public static string Addr3(XElement n)
 {
     string addre3 = "";
     if (n.Element("AddressLine3") != null)
         addre3 = (string)n.Element("AddressLine3");
     return addre3;
 }
开发者ID:JMS1,项目名称:Hygiene,代码行数:7,代码来源:UtilityFunctions.cs

示例3: EnumDefinition

        /// <summary>
        /// Initializes a new instance of the EnumDefinition class
        /// Populates this object with information extracted from the XML
        /// </summary>
        /// <param name="theNode">XML node describing the Enum object</param>
        /// <param name="manager">The data dictionary manager constructing this type.</param>
        public EnumDefinition(XElement theNode, DictionaryManager manager)
            : base(theNode, TypeId.EnumType)
        {
            // ByteSize may be set either directly as an integer or by inference from the Type field.
            // If no Type field is present then the type is assumed to be 'int'
            if (theNode.Element("ByteSize") != null)
            {
                SetByteSize(theNode.Element("ByteSize").Value);
            }
            else
            {
                string baseTypeName = theNode.Element("Type") != null ? theNode.Element("Type").Value : "int";

                BaseType = manager.GetElementType(baseTypeName);
                BaseType = DictionaryManager.DereferenceTypeDef(BaseType);

                FixedSizeBytes = BaseType.FixedSizeBytes.Value;
            }

            // Common properties are parsed by the base class.
            // Remaining properties are the Name/Value Literal elements
            List<LiteralDefinition> theLiterals = new List<LiteralDefinition>();
            foreach (var literalNode in theNode.Elements("Literal"))
            {
                theLiterals.Add(new LiteralDefinition(literalNode));
            }

            m_Literals = new ReadOnlyCollection<LiteralDefinition>(theLiterals);

            // Check the name. If it's null then make one up
            if (theNode.Element("Name") == null)
            {
                Name = String.Format("Enum_{0}", Ref);
            }
        }
开发者ID:DaveRobSwEng,项目名称:CSharpUtilities,代码行数:41,代码来源:EnumDefinition.cs

示例4: GetMethodSignature

        /// <summary>
        /// Gets the method signature from the method definition srcML element.
        /// </summary>
        /// <param name="methodElement">The srcML method element to extract the signature from.</param>
        /// <returns>The method signature</returns>
        public static string GetMethodSignature(XElement methodElement) {
            if(methodElement == null) {
                throw new ArgumentNullException("methodElement");
            }
            if(!(new[] { SRC.Function, SRC.Constructor, SRC.Destructor }).Contains(methodElement.Name)) {
                throw new ArgumentException(string.Format("Not a valid method element: {0}", methodElement.Name), "methodElement");
            }

            var sig = new StringBuilder();
            var lastSigElement = methodElement.Element(SRC.ParameterList);
            if(lastSigElement == null) {
                lastSigElement = methodElement.Element(SRC.Name);
            }
            if(lastSigElement != null) {
                //add all the text and whitespace prior to the last element
                foreach(var n in lastSigElement.NodesBeforeSelf()) {
                    if(n.NodeType == XmlNodeType.Element) {
                        sig.Append(((XElement)n).Value);
                    } else if(n.NodeType == XmlNodeType.Text || n.NodeType == XmlNodeType.Whitespace || n.NodeType == XmlNodeType.SignificantWhitespace) {
                        sig.Append(((XText)n).Value);
                    }
                }
                //add the last element
                sig.Append(lastSigElement.Value);
            } else {
                //no name or parameter list, anonymous method?
            }

            //convert whitespace chars to spaces and condense any consecutive whitespaces.
            return Regex.Replace(sig.ToString().Trim(), @"\s+", " ");
        }
开发者ID:nkcsgexi,项目名称:SrcML.NET,代码行数:36,代码来源:SrcMLElement.cs

示例5: PauseScreen

        public PauseScreen(XElement reader, string basePath)
        {
            weapons = new List<PauseWeaponInfo>();
            inventory = new List<InventoryInfo>();

            XElement changeNode = reader.Element("ChangeSound");
            if (changeNode != null) ChangeSound = SoundInfo.FromXml(changeNode, basePath);

            XElement soundNode = reader.Element("PauseSound");
            if (soundNode != null) PauseSound = SoundInfo.FromXml(soundNode, basePath);

            XElement backgroundNode = reader.Element("Background");
            if (backgroundNode != null) Background = FilePath.FromRelative(backgroundNode.Value, basePath);

            foreach (XElement weapon in reader.Elements("Weapon"))
                weapons.Add(PauseWeaponInfo.FromXml(weapon, basePath));

            XElement livesNode = reader.Element("Lives");
            if (livesNode != null)
            {
                LivesPosition = new Point(livesNode.GetInteger("x"), livesNode.GetInteger("y"));
            }

            foreach (XElement inventoryNode in reader.Elements("Inventory"))
            {
                inventory.Add(InventoryInfo.FromXml(inventoryNode, basePath));
            }
        }
开发者ID:Tesserex,项目名称:CME-Common-Library,代码行数:28,代码来源:PauseScreen.cs

示例6: GetBroadcast

		private Broadcast GetBroadcast(XElement xml) {
			DateTime startTime=TimeZoneInfo.ConvertTime(
				DateTime.ParseExact(xml.Element("date_prog").Value, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
				timezone, TimeZoneInfo.Local);
			string caption=xml.Element("chanson").Value;
			return new Broadcast(startTime, startTime.AddSeconds(TimerTimeout), allCapsRx.IsMatch(caption) ? caption.ToCapitalized():caption);
		}
开发者ID:drdax,项目名称:Radio,代码行数:7,代码来源:EuronewsGuide.cs

示例7: BindCollection

        private static void BindCollection(object model, Type modelType, string prefix, XElement properties)
        {
            var element = properties.Element(d + prefix + CountSuffix);

            if (element == null || string.IsNullOrEmpty(element.Value))
            {
                return;
            }

            var count = (int)element;

            for (int i = 0; i < count; i++)
            {
                var value = default(object);

                if (!TypeHelpers.IsComplexType(modelType))
                {
                    var elem = properties.Element(d + prefix + Separator + i);

                    if (elem != null)
                    {
                        value = TypeDescriptor.GetConverter(modelType).ConvertFrom(elem.Value);
                    }
                }
                else
                {
                    value = TypeHelpers.Create(modelType);

                    BindModel(value, modelType, prefix + Separator + i, properties);
                }

                ((IList)model).Add(value);
            }
        }
开发者ID:shibayan,项目名称:WATableComplexType,代码行数:34,代码来源:ComplexTypeTableServiceContext.cs

示例8: ImportFromXml

        /// <summary>
        /// Imports the <see cref="ManagedAuthenticatedEncryptorDescriptor"/> from serialized XML.
        /// </summary>
        public IAuthenticatedEncryptorDescriptor ImportFromXml(XElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            // <descriptor>
            //   <!-- managed implementations -->
            //   <encryption algorithm="..." keyLength="..." />
            //   <validation algorithm="..." />
            //   <masterKey>...</masterKey>
            // </descriptor>

            var settings = new ManagedAuthenticatedEncryptionSettings();

            var encryptionElement = element.Element("encryption");
            settings.EncryptionAlgorithmType = FriendlyNameToType((string)encryptionElement.Attribute("algorithm"));
            settings.EncryptionAlgorithmKeySize = (int)encryptionElement.Attribute("keyLength");

            var validationElement = element.Element("validation");
            settings.ValidationAlgorithmType = FriendlyNameToType((string)validationElement.Attribute("algorithm"));

            Secret masterKey = ((string)element.Element("masterKey")).ToSecret();

            return new ManagedAuthenticatedEncryptorDescriptor(settings, masterKey, _services);
        }
开发者ID:yonglehou,项目名称:DataProtection,代码行数:30,代码来源:ManagedAuthenticatedEncryptorDescriptorDeserializer.cs

示例9: ConvertXmlToRss

        public static IEnumerable<RssItem> ConvertXmlToRss(XElement feed, int count)
        {
            XNamespace ns = "http://www.w3.org/2005/Atom";

            // see if RSS or Atom

            // RSS
            if (feed.Element("channel") != null)
                return (from item in feed.Element("channel").Elements("item")
                        select new RssItem
                        {
                            Title = StripTags(item.Element("title").Value, 200),
                            Link = item.Element("link").Value,
                            Description = StripTags(item.Element("description").Value, 200)
                        }).Take(count);

            // Atom
            else if (feed.Element(ns + "entry") != null)
                return (from item in feed.Elements(ns + "entry")
                        select new RssItem
                        {
                            Title = StripTags(item.Element(ns + "title").Value, 200),
                            Link = item.Element(ns + "link").Attribute("href").Value,
                            Description = StripTags(item.Element(ns + "content").Value, 200)
                        }).Take(count);

            // Invalid
            else
                return null;
        }
开发者ID:modulexcite,项目名称:dropthings,代码行数:30,代码来源:RssHelper.cs

示例10: ParseJournal

        public IEnumerable<Journal> ParseJournal(XElement recordElement)
        {
            var regularJournal = new Journal
            {
                Title = recordElement.Element("Title").Value,
                ISSN = recordElement.Element("ISSN").Value,
                Link = recordElement.Element("JournalWebsiteURL").Value,
                Publisher = ParsePublisher(recordElement),
                Country = ParseCountry(recordElement),
                Languages = this.ParseLanguages(recordElement),
                Subjects = this.ParseSubjects(recordElement),
                DataSource = JournalsImportSource.Ulrichs.ToString(),
                OpenAccess = IsOpenAccessJournal(recordElement)
            };

            yield return regularJournal;

            foreach (var alternateEditionElement in GetAlternateEditionElements(recordElement))
            {
                yield return new Journal
                {
                    Title = regularJournal.Title,
                    ISSN = alternateEditionElement.Element("ISSN").Value,
                    Link = regularJournal.Link,
                    Publisher = ParsePublisher(recordElement),
                    Country = ParseCountry(recordElement),
                    Languages = this.ParseLanguages(recordElement),
                    Subjects = this.ParseSubjects(recordElement),
                    DataSource = JournalsImportSource.Ulrichs.ToString(),
                    OpenAccess = IsOpenAccessJournal(recordElement)
                };
            }
        }
开发者ID:spapaseit,项目名称:qoam,代码行数:33,代码来源:UlrichsImport.cs

示例11: Read

        private static EDM Read(XElement edmx, Action<XElement> readMoreAction)
        {
            XElement edmxRuntime = edmx.Element(XName.Get("Runtime", edmxNamespace.NamespaceName));

            SSDLContainer ssdlContainer = SSDLIO.ReadXElement(edmxRuntime);
            CSDLContainer csdlContainer = CSDLIO.ReadXElement(edmxRuntime);
            XElement edmxDesigner = edmx.Element(XName.Get("Designer", edmxNamespace.NamespaceName));
            
            if (ssdlContainer == null && csdlContainer == null)
            	return new EDM();

            EDM edm = new EDM()
            {
                SSDLContainer = ssdlContainer,
                CSDLContainer = MSLIO.IntegrateMSLInCSDLContainer(csdlContainer, ssdlContainer, edmxRuntime),
            };

            if (edmxDesigner != null)
            {
                if (edmxDesigner.Element(XName.Get("Connection", edmxNamespace.NamespaceName)) != null)
                    edm.DesignerProperties = edmxDesigner.Element(XName.Get("Connection", edmxNamespace.NamespaceName)).Element(XName.Get("DesignerInfoPropertySet", edmxNamespace.NamespaceName)).Elements(XName.Get("DesignerProperty", edmxNamespace.NamespaceName)).Select(e => new DesignerProperty { Name = e.Attribute("Name").Value, Value = e.Attribute("Value").Value });

                if (edmxDesigner.Element(XName.Get("Options", edmxNamespace.NamespaceName)) != null)
                    edm.EDMXDesignerDesignerProperties = edmxDesigner.Element(XName.Get("Options", edmxNamespace.NamespaceName)).Element(XName.Get("DesignerInfoPropertySet", edmxNamespace.NamespaceName)).Elements(XName.Get("DesignerProperty", edmxNamespace.NamespaceName)).Select(e => new DesignerProperty { Name = e.Attribute("Name").Value, Value = e.Attribute("Value").Value });

                if (edmxDesigner.Element(XName.Get("Diagrams", edmxNamespace.NamespaceName)) != null)
                    edm.EDMXDesignerDiagrams = edmxDesigner.Element(XName.Get("Diagrams", edmxNamespace.NamespaceName)).Elements(XName.Get("Diagram", edmxNamespace.NamespaceName));
            }

            readMoreAction(edmx);
            return edm;
        }
开发者ID:ootsby,项目名称:SharpDevelop,代码行数:32,代码来源:EDMXIO.cs

示例12: LoadFromXml

 internal override void LoadFromXml(XElement xRoot)
 {
     if (xRoot != null && xRoot.Element(XmlConstants.ReceivedMessage) != null)
     {
         ReceivedMessage = xRoot.Element(XmlConstants.ReceivedMessage).Value;
     }
 }
开发者ID:Catrobat,项目名称:CatrobatForWindows,代码行数:7,代码来源:XmlBroadcastScript.cs

示例13: ImportFromXml

        /// <summary>
        /// Imports the <see cref="CngCbcAuthenticatedEncryptorDescriptor"/> from serialized XML.
        /// </summary>
        public IAuthenticatedEncryptorDescriptor ImportFromXml(XElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            // <descriptor>
            //   <!-- Windows CNG-CBC -->
            //   <encryption algorithm="..." keyLength="..." [provider="..."] />
            //   <hash algorithm="..." [provider="..."] />
            //   <masterKey>...</masterKey>
            // </descriptor>

            var settings = new CngCbcAuthenticatedEncryptionSettings();

            var encryptionElement = element.Element("encryption");
            settings.EncryptionAlgorithm = (string)encryptionElement.Attribute("algorithm");
            settings.EncryptionAlgorithmKeySize = (int)encryptionElement.Attribute("keyLength");
            settings.EncryptionAlgorithmProvider = (string)encryptionElement.Attribute("provider"); // could be null

            var hashElement = element.Element("hash");
            settings.HashAlgorithm = (string)hashElement.Attribute("algorithm");
            settings.HashAlgorithmProvider = (string)hashElement.Attribute("provider"); // could be null

            Secret masterKey = ((string)element.Element("masterKey")).ToSecret();

            return new CngCbcAuthenticatedEncryptorDescriptor(settings, masterKey, _services);
        }
开发者ID:yonglehou,项目名称:DataProtection,代码行数:32,代码来源:CngCbcAuthenticatedEncryptorDescriptorDeserializer.cs

示例14: AuthName

 public static string AuthName(XElement n)
 {
     string authName = "";
     if (n.Element("LocalAuthorityName") != null)
         authName = (string)n.Element("LocalAuthorityName");
     return authName;
 }
开发者ID:JMS1,项目名称:Hygiene,代码行数:7,代码来源:UtilityFunctions.cs

示例15: Addr4

 public static string Addr4(XElement n)
 {
     string addre4 = "";
     if (n.Element("AddressLine4") != null)
         addre4 = (string)n.Element("AddressLine4");
     return addre4;
 }
开发者ID:JMS1,项目名称:Hygiene,代码行数:7,代码来源:UtilityFunctions.cs


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