當前位置: 首頁>>代碼示例>>C#>>正文


C# XElement.Elements方法代碼示例

本文整理匯總了C#中System.Xml.Linq.XElement.Elements方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.Elements方法的具體用法?C# XElement.Elements怎麽用?C# XElement.Elements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.Elements方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: RemoveElement

        private XElement RemoveElement(XElement input)
        {
            XElement output = new XElement("objects", new XAttribute("filename", input.Element("filename").Value));
            Random rand = new Random();
            int outElement = rand.Next(input.Elements("object").Count());

            XElement element = input.Element("object");
            for (int i = 0; i < input.Elements("object").Count(); i++)
            {
                if (element.Element("name") != null)
                {

                    if (i != outElement)
                    {
                        output.Add(new XElement("object", new XAttribute("name", element.Element("name").Value.ToLower().Replace("\n", "").Replace("\b", ""))));
                    }
                    else
                    {
                        output.Add(new XElement("result", new XAttribute("name", element.Element("name").Value.ToLower().Replace("\n", "").Replace("\b", ""))));
                    }
                }
                element = (XElement)element.NextNode;
            }

            return output;
        }
開發者ID:stgolarrain,項目名稱:MNNsOntology,代碼行數:26,代碼來源:Test.cs

示例2: RewriteElement

		bool RewriteElement(XamlContext ctx, XElement parent, XElement elem) {
			var type = parent.Annotation<XamlType>();
			var property = elem.Annotation<XamlProperty>();
			if ((property == null || type == null) && elem.Name != key)
				return false;

			if (elem.Elements().Count() != 1 || elem.Attributes().Any(t => t.Name.Namespace != XNamespace.Xmlns))
				return false;

			var value = elem.Elements().Single();

			if (!CanInlineExt(ctx, value))
				return false;

			var ext = InlineExtension(ctx, value);
			if (ext == null)
				return false;

			ctx.CancellationToken.ThrowIfCancellationRequested();

			var extValue = ext.ToString(ctx, parent);

			var attrName = elem.Name;
			if (attrName != key)
				attrName = property.ToXName(ctx, parent, property.IsAttachedTo(type));
			var attr = new XAttribute(attrName, extValue);
			parent.Add(attr);
			elem.Remove();

			return true;
		}
開發者ID:GreenDamTan,項目名稱:dnSpy,代碼行數:31,代碼來源:MarkupExtensionRewritePass.cs

示例3: 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

示例4: Parse

		public static void Parse(dynamic parent, XElement node)
		{
			foreach (var a in node.Attributes())
				AddProperty(parent, a.Name.ToString(), a.Value);
			if (node.HasElements)
			{
				IEnumerable<XElement> sorted = from XElement elt in node.Elements() orderby node.Elements(elt.Name.LocalName).Count() descending select elt;
				string elementName = string.Empty;
				List<dynamic> list = null;
				foreach (var element in sorted)
				{
					var item = new ExpandoObject();
					Parse(item, element);
					if (element.Name.LocalName != elementName)
					{
						list = null;
						AddProperty(parent, elementName = element.Name.LocalName, item);
					}
					else
						if (list == null)
							AddProperty(parent, element.Name.LocalName, list = new List<dynamic>() { (parent as IDictionary<string, object>)[element.Name.LocalName], item });
						else
							list.Add(item);
				}
			}
			else if (!string.IsNullOrWhiteSpace(node.Value))
				AddProperty(parent, "TextValue", node.Value.Trim());
		}
開發者ID:xCMNx,項目名稱:BooruViewer.Net,代碼行數:28,代碼來源:XmlToDynamic.cs

示例5: Execute

        /// <summary>
        /// Execute
        /// </summary>
        /// <param name="loopTag"></param>
        /// <param name="exchange"></param>
        /// <param name="route"></param>
        public static void Execute(XElement loopTag, Exchange exchange, Route route)
        {
            Camel.TryLog(exchange, "processor", "loop");
            var expressionTag = loopTag.Elements().FirstOrDefault();
            if (expressionTag == null || (expressionTag.Name != "count"))
                return;

            var xpression = expressionTag.Value;
            var count = SimpleExpression.ResolveSpecifiedUriPart(xpression, exchange);

            var mCount = Convert.ToInt32(count);
            for (var i = 0; i < mCount; i++)
            {
                var data = loopTag.Elements().Skip(1);
                foreach (var dataItem in data)
                {
                    try
                    {
                        RouteStep.ProcessStep(dataItem, route, exchange);
                    }
                    catch (Exception exception)
                    {

                    }
                }
            }
        }
開發者ID:ojoadeolagabriel,項目名稱:TqWorkflow-beta,代碼行數:33,代碼來源:LoopTag.cs

示例6: ParseSingleXsdl

        /// <summary>
        /// Parses a single csdl/ssdl file.
        /// </summary>
        /// <param name="model">the entity model schema which the csdl/ssdl file parses to</param>
        /// <param name="schemaElement">the top level schema element in the csdl/ssdl file</param>
        protected virtual void ParseSingleXsdl(EntityModelSchema model, XElement schemaElement)
        {
            this.AssertXsdlElement(schemaElement, "Schema");

            this.SetupNamespaceAndAliases(schemaElement);

            foreach (var entityContainerElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityContainer")))
            {
                model.Add(this.ParseEntityContainer(entityContainerElement));
            }

            foreach (var entityTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityType")))
            {
                model.Add(this.ParseEntityType(entityTypeElement));
            }

            foreach (var associationTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Association")))
            {
                model.Add(this.ParseAssociation(associationTypeElement));
            }

            foreach (var functionElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Function")))
            {
                model.Add(this.ParseFunction(functionElement));
            }
        }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:31,代碼來源:XsdlParserBase.cs

示例7: LoadFromXml

        public void LoadFromXml(XElement xmlElement)
        {
            IdManager idManager = IdManager.GetIdManager();

            InventoryItems = new List<InventoryItem>();

            foreach (XElement inventoryItemsElement in xmlElement.Elements("InventoryItems"))
            {
                foreach (XElement inventoryItemElement in inventoryItemsElement.Elements("InventoryItem"))
                {
                    InventoryItem inventoryItem = new InventoryItem();

                    inventoryItem.LoadFromXml(inventoryItemElement);

                    InventoryItems.Add(inventoryItem);
                }
            }

            foreach (var locationsElement in xmlElement.Elements("Locations"))
            {
                foreach (var locationElement in locationsElement.Elements("Location"))
                {
                    Location location = new Location();

                    location.LoadFromXml(locationElement);

                    Locations.Add(location);

                    idManager.RegisterId(location, location.Id);
                }
            }

            MerryUpLocationsWithInventoryItems();
        }
開發者ID:fernandozamoraj,項目名稱:XML-Project-For-Masters-Course,代碼行數:34,代碼來源:Inventory.cs

示例8: UserInfo

        public UserInfo(XElement element)
        {
            this.Name = element.Element("name").Value;
            this.id = Int32.Parse(element.Element("id").Value);
            this.url = new Uri(element.Element("url").Value);

            if (element.Element("realname") != null && element.Element("realname").Value != null)
                this.RealName = element.Element("realname").Value;
            if (element.Element("age") != null && !String.IsNullOrEmpty(element.Element("age").Value))
                this.Age = Int32.Parse(element.Element("age").Value);
            if (element.Element("playcount") != null)
                this.PlayCount = Int32.Parse(element.Element("playcount").Value);
            try
            { this.SmallImage = new Uri((from el in element.Elements("image") where el.Attribute("size").Value.ToString() == "small" select el.Value.ToString()).First()); }
            catch (UriFormatException) { this.SmallImage = null; }
            try
            { this.MediumImage = new Uri((from el in element.Elements("image") where el.Attribute("size").Value.ToString() == "medium" select el.Value.ToString()).First()); }
            catch (UriFormatException) { this.MediumImage = null; }
            try
            { this.LargeImage = new Uri((from el in element.Elements("image") where el.Attribute("size").Value.ToString() == "large" select el.Value.ToString()).First()); }
            catch (UriFormatException) { this.LargeImage = null; }
            try
            { this.ExtraLargeImage = new Uri((from el in element.Elements("image") where el.Attribute("size").Value.ToString() == "extralarge" select el.Value.ToString()).First()); }
            catch (UriFormatException) { this.ExtraLargeImage = null; }
        }
開發者ID:passick,項目名稱:wp.fm,代碼行數:25,代碼來源:UserInfo.cs

示例9: ProcessElement

        static void ProcessElement(Counter counter, XElement element, Node rootNode)
        {
            foreach (XElement e in element.Elements("File"))
            {
                XAttribute attribute = e.Attribute("RelativePath");
                if (attribute == null)
                    continue;

                FileNode file = new FileNode();
                file.Path = Path.Combine(Path.GetDirectoryName(projectPath), attribute.Value);
                counter.CountFile(file);

                if (file.Valid)
                    rootNode.ChildNodes.Add(file);
            }

            foreach (XElement e in element.Elements("Filter"))
            {
                XAttribute attribute = e.Attribute("Name");
                if (attribute == null)
                    continue;

                Node node = new Node();
                node.Name = attribute.Value;
                ProcessElement(counter, e, node);

                rootNode.ChildNodes.Add(node);
            }
        }
開發者ID:zhandb,項目名稱:slimdx,代碼行數:29,代碼來源:VCProject.cs

示例10: Parse

        public static void Parse(dynamic parent, XElement node)
        {
            if (node.HasElements)
                if (node.Elements(node.Elements().First().Name.LocalName).Count() > 1)
                {
                    //list
                    var item = new ExpandoObject();
                    var list = new List<dynamic>();
                    foreach (var element in node.Elements())
                        Parse(list, element);

                    AddProperty(item, node.Elements().First().Name.LocalName, list);
                    AddProperty(parent, node.Name.ToString(), item);
                }
                else
                {
                    var item = new ExpandoObject();

                    foreach (var attribute in node.Attributes())
                        AddProperty(item, attribute.Name.ToString(), attribute.Value.Trim());

                    //element
                    foreach (var element in node.Elements())
                        Parse(item, element);

                    AddProperty(parent, node.Name.ToString(), item);
                }
            else
                AddProperty(parent, node.Name.ToString(), node.Value.Trim());
        }
開發者ID:risedphantom,項目名稱:MassMailer,代碼行數:30,代碼來源:DynamicXml.cs

示例11: addDate

        //wird nicht gebraucht (fetch bookings with Dates)
        public static XElement addDate(XElement xmlString, String from, String dto)
        {
            //version 1 
                //XElement dateXml = getXmlFile(System.IO.Path.Combine(@"..\..\xml-Strings\alternativeStringDate.xml"));
            
                //dateXml.Elements("value").Elements("array").Elements("data").Elements("value")
                //    .Elements("struct").Elements("member").Take(1).Elements("value").Elements("string")
                //    .LastOrDefault().Add(from);

                //dateXml.Elements("value").Elements("array").Elements("data").Elements("value")
                //   .Elements("struct").Elements("member").Take(2).Elements("value").Elements("string")
                //   .LastOrDefault().Add(dto);
  
            //version 2
            XElement date1 = new XElement("param",
                                    new XElement("value",
                                        new XElement("string",from
                                            )));
            XElement date2 = new XElement("param",
                                   new XElement("value",
                                       new XElement("string", dto
                                           )));

            xmlString.Elements("params").Take(3).LastOrDefault().AddAfterSelf(date1);
            xmlString.Elements("params").Take(3).LastOrDefault().AddAfterSelf(date2);

            return xmlString;
        }
開發者ID:hrmKoal,項目名稱:HRMdiplArbeit_Pilz,代碼行數:29,代碼來源:Wired_XMLRpc.cs

示例12: ParseDocument

        private string ParseDocument(XElement document)
        {
            StringBuilder result = new StringBuilder();
            IEnumerable<XElement> obxSegments = document.Elements("OBX");
            foreach (XElement obxSegment in obxSegments)
            {
                XElement obx5 = obxSegment.Element("OBX.5");
                XElement obx51 = obx5.Element("OBX.5.1");
                if (obx51 != null)
                {
                    result.AppendLine(obx51.Value);
                }
                else
                {
                    result.AppendLine();
                }
            }

            IEnumerable<XElement> nteSegments = document.Elements("NTE");
            foreach (XElement nteSegment in nteSegments)
            {
                XElement nte3 = nteSegment.Element("NTE.3");
                if (nte3 != null)
                {
                    XElement nte31 = nte3.Element("NTE.3.1");
                    result.AppendLine(nte31.Value);
                }
                else
                {
                    result.AppendLine();
                }
            }

            return result.ToString();
        }
開發者ID:WilliamCopland,項目名稱:YPILIS,代碼行數:35,代碼來源:Hl7ResultDialog.xaml.cs

示例13: ProcessAttachElement

 private static bool ProcessAttachElement(XElement attach)
 {
     // Basic lement is here - it is namespace which we add to all element names
     XNamespace ns = "http://schemas.microsoft.com/exchange/services/2006/types";
     bool hasChanges = false;
     if (!attach.Elements().Any(el => el.Name.LocalName == "LastModifiedTime"))
     {
         XElement elem = new XElement(ns + "LastModifiedTime");
         elem.Name = ns + "LastModifiedTime";
         elem.Value = "2015-11-30T13:29:11.6088823+03:00";
         attach.Add(elem);
         hasChanges = true;
     }
     if (!attach.Elements().Any(el => el.Name.LocalName == "IsContactPhoto"))
     {
         XElement elem = new XElement(ns + "IsContactPhoto");
         elem.Name = ns +"IsContactPhoto";
         elem.Value = "false";
         attach.Add(elem);
         hasChanges = true;
     }
     else
     {
         if (attach.Elements().First(el => el.Name.LocalName == "IsContactPhoto").Value == "False")
         {
             attach.Elements().First(el => el.Name.LocalName == "IsContactPhoto").Value = "false";
             hasChanges = true;
         }
     }
     return hasChanges;
 }
開發者ID:shukanov-artyom,項目名稱:studies,代碼行數:31,代碼來源:Program.cs

示例14: WebDavResponse

        public WebDavResponse(XElement response)
        {
            if (response == null)
                throw new ArgumentNullException ("response");

            Element = response;

            Href    = response.GetElementPathValue (WebDavNames.Href);
            Hrefs   = response.Elements (WebDavNames.Href)
                .Select (h => h.Value)
                .Skip (1);
            if (Hrefs.Any ()) {
                Status              = response.GetElementPathValue (WebDavNames.Status);
                PropertyStatuses    = new WebDavPropertyStatus [0];
            }
            else {
                PropertyStatuses = response.Elements (WebDavNames.Propstat)
                    .Select (propstat => new WebDavPropertyStatus (propstat));
            }

            Error = response.GetElementPath (WebDavNames.Error);
            if (Error != null)
                Error = Error.Elements ().FirstOrDefault ();

            ResponseDescription = response.GetElementPathValue (WebDavNames.ResponseDescription);
            Location            = response.GetElementPathValue (WebDavNames.Location, WebDavNames.Href);
        }
開發者ID:Clearic,項目名稱:WebDavClient,代碼行數:27,代碼來源:WebDavResponse.cs

示例15: ReadPackage

        private LoadPackage ReadPackage(XElement pkge) {
            var result = new LoadPackage {Code = pkge.Attr("code")};
            var level = pkge.Attr("level");
            if (!string.IsNullOrWhiteSpace(level)) {
                result.Level = (LoadLevel) Enum.Parse(typeof (LoadLevel), level, true);
            }

            result.Arm = pkge.Attr("arm","default");
            result.Command = pkge.Attr("command", "");
               

            var deps = pkge.Elements("uses");
            foreach (var dep in deps) {
                result.Dependency.Add(dep.Attr("code"));
            }
            foreach (var item in pkge.Elements("load")) {
                result.Items.Add(ReadItem(item));
            }
            foreach (var item in pkge.Elements("widget")) {
                ReadWidget(result, item);
            }


            return result;
        }
開發者ID:Qorpent,項目名稱:qorpent.sys,代碼行數:25,代碼來源:LoadPackageReader.cs


注:本文中的System.Xml.Linq.XElement.Elements方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。