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


C# XElement.Add方法代码示例

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


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

示例1: AncestorsWithXNameBeforeAndAfter

 public static void AncestorsWithXNameBeforeAndAfter()
 {
     XText aText = new XText("a"), bText = new XText("b");
     XElement a = new XElement("A", aText), b = new XElement("B", bText);
     a.Add(b);
     IEnumerable<XElement> nodes = bText.Ancestors("B");
     Assert.Equal(1, nodes.Count());
     bText.Remove(); a.Add(bText);
     Assert.Equal(0, nodes.Count());
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:AxisOrderValidation.cs

示例2: ThemaCompilerResultForQweb

		public ThemaCompilerResultForQweb(ThemaCompilerContext context) {
			IsComplete = context.IsComplete;
			Errors = context.Errors.ToArray();
			if (!IsComplete) return;
			var r = new XElement("result");
			foreach (var t in context.Themas.Values.Where(t => null != t.Xml)) {
				r.Add(t.Xml);
			}
			if (null != context.ExtraData) {
				r.Add(context.ExtraData);
			}
			Result = new XmlToBxlConverter().Convert(r);
			Log = context.Project.GetLog();
		}
开发者ID:comdiv,项目名称:qorpent.themas,代码行数:14,代码来源:ThemaCompilerResultForQweb.cs

示例3: Main

        private static void Main()
        {
            helper.ConsoleMio.Setup();
            helper.ConsoleMio.PrintHeading("Extract Contact Information");

            string selctedFile = SelectFileToOpen();

            string saveLocation = SelectSaveLocation();

            var contactInfo = new XElement("person");
            
            using (var inputStream = new StreamReader(selctedFile))
            {
                string currentLine;
                while ((currentLine = inputStream.ReadLine()) != null)
                {
                    string[] args = currentLine.Split(' ');
                    string tag = args[0];
                    string content = string.Join(" ", args.Skip(1).ToArray());

                    contactInfo.Add(new XElement(tag, content));
                }
            }

            contactInfo.Save(saveLocation);

            helper.ConsoleMio.PrintColorText("Completed\n ", ConsoleColor.Green);
            
            helper.ConsoleMio.Restart(Main);
        }
开发者ID:kidroca,项目名称:Databases,代码行数:30,代码来源:ParseTextXml.cs

示例4: ElementsAfterSelfWithXNameBeforeAndAfter

 public static void ElementsAfterSelfWithXNameBeforeAndAfter()
 {
     XText aText = new XText("a"), bText = new XText("b");
     XElement a = new XElement("A", aText), b = new XElement("B", bText);
     a.Add(b);
     IEnumerable<XElement> nodes = aText.ElementsAfterSelf("B");
     Assert.Equal(1, nodes.Count());
     b.ReplaceWith(a);
     Assert.Equal(0, nodes.Count());
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:AxisOrderValidation.cs

示例5: CData

        public void CData(string value1, string value2, bool checkHashCode)
        {
            XCData t1 = new XCData(value1);
            XCData t2 = new XCData(value2);
            VerifyComparison(checkHashCode, t1, t2);

            XElement e2 = new XElement("p2p", t2);
            e2.Add(t1);
            VerifyComparison(checkHashCode, t1, t2);
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:10,代码来源:DeepEquals.cs

示例6: ToXElement

        /// <summary>
        /// Converts a given <see cref="Account"/> into an <see cref="T:XElement"/>.
        /// </summary>
        /// <param name="account">The <see cref="Account"/> to convert.</param>
        /// <returns>The newly created <see cref="T:XElement"/>.</returns>
        public XElement ToXElement(Account account)
        {
            XElement element = new XElement(account.AccountType.ToString());
            element.Add(new XElement("AccountID", account.AccountID));
            element.Add(new XElement("CreatedByUsername", account.CreatedByUsername));
            element.Add(new XElement("CreatedDate", account.CreatedDate));
            element.Add(new XElement("Description", account.Description));
            element.Add(new XElement("Name", account.Name));
            element.Add(new XElement("UpdatedByUsername", account.UpdatedByUsername));
            element.Add(new XElement("UpdatedDate", account.UpdatedDate));

            // Append the change history
            ChangeSetHistoryXElementAdapter adapter = new ChangeSetHistoryXElementAdapter();
            element.Add(adapter.ToXElement(account.ChangeSetHistory));

            return element;
        }
开发者ID:PaulStovell,项目名称:trial-balance,代码行数:22,代码来源:AccountXElementAdapter.cs

示例7: GetLog

 public XElement GetLog() 
 {
     int id = GetIdFromHeaders();
     PTEntities ctx = this.CurrentDataSource;
     TestOperation t = ctx.TestOperations.Include("LogEntries.LogEntryHeaders").FirstOrDefault(to => (to.Id == id));
     if (t == null) return null;
     XElement retVal = new XElement("TestOperation", new XAttribute("id", id), new XAttribute("desc", t.Name));
     foreach (var le in t.LogEntries) 
     {
         XElement xle = new XElement(le.Verb, new XAttribute("Uri", le.URI));
         retVal.Add(xle);
         foreach (var leh in le.LogEntryHeaders) 
         {
             xle.Add(new XElement("Header", new XAttribute("key", leh.Header), new XAttribute("value", leh.Value)));
         }
     }
     return retVal;
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:18,代码来源:PicturesTagsEdm.res.cs

示例8: ToXElement

 /// <summary>
 /// Converts a given <see cref="ChangeSetHistory"/> into an <see cref="T:XElement"/>.
 /// </summary>
 /// <param name="changeSetHistory">The <see cref="ChangeSetHistory"/> to convert.</param>
 /// <returns>The newly created <see cref="T:XElement"/>.</returns>
 public XElement ToXElement(ChangeSetHistory changeSetHistory)
 {
     XElement historyElement = new XElement("ChangeSetHistory");
     foreach (ChangeSet changeSet in changeSetHistory) {
         XElement changeSetElement = new XElement("ChangeSet",
             new XElement("Applied", changeSet.Applied),
             new XElement("Username", changeSet.Username));
         foreach (Change change in changeSet.Changes) {
             XElement changeElement = new XElement("Change",
                 new XElement("PropertyName", change.PropertyName),
                 new XElement("OldValue", change.OldValue),
                 new XElement("NewValue", change.NewValue));
             changeSetElement.Add(changeElement);
         }
         historyElement.Add(changeSetElement);
     }
     return historyElement;
 }
开发者ID:PaulStovell,项目名称:trial-balance,代码行数:23,代码来源:ChangeSetHistoryXElementAdapter.cs

示例9: DescendantsWithXNameOnXElementBeforeAndAfter

 public static void DescendantsWithXNameOnXElementBeforeAndAfter()
 {
     XElement a = new XElement("A", "a"), b = new XElement("B", "b");
     a.Add(b);
     IEnumerable<XElement> nodes = a.Descendants("B");
     Assert.Equal(1, nodes.Count());
     b.Remove();
     Assert.Equal(0, nodes.Count());
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:9,代码来源:AxisOrderValidation.cs

示例10: ElementsWithXNameOnXElementBeforeAndAfter

 public static void ElementsWithXNameOnXElementBeforeAndAfter()
 {
     XElement a = new XElement("A", "a"), b = new XElement("B", "b");
     IEnumerable<XElement> nodes = a.Elements("B");
     Assert.Equal(0, nodes.Count());
     a.Add(b, b, b, b);
     Assert.Equal(4, nodes.Count());
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:8,代码来源:AxisOrderValidation.cs

示例11: NodesOnXElementBeforeAndAfter

 public static void NodesOnXElementBeforeAndAfter()
 {
     XElement a = new XElement("A", "a"), b = new XElement("B", "b");
     a.Add(b);
     IEnumerable<XNode> nodes = a.Nodes();
     Assert.Equal(2, nodes.Count());
     b.Remove();
     Assert.Equal(1, nodes.Count());
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:9,代码来源:AxisOrderValidation.cs

示例12: DescendantsOnXDocBeforeAndAfter

 public static void DescendantsOnXDocBeforeAndAfter()
 {
     XElement a = new XElement("A", "a"), b = new XElement("B", "b");
     a.Add(b);
     XDocument xDoc = new XDocument(a);
     IEnumerable<XElement> nodes = xDoc.Descendants("B");
     Assert.Equal(1, nodes.Count());
     b.Remove();
     Assert.Equal(0, nodes.Count());
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:AxisOrderValidation.cs

示例13: AncestorsAndSelfWithXNameBeforeAndAfter

 public static void AncestorsAndSelfWithXNameBeforeAndAfter()
 {
     XElement a = new XElement("A", "a"), b = new XElement("B", "b");
     a.Add(b);
     IEnumerable<XElement> nodes = b.AncestorsAndSelf("A");
     Assert.Equal(1, nodes.Count());
     XElement c = new XElement("A", "a", a);
     Assert.Equal(2, nodes.Count());
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:9,代码来源:AxisOrderValidation.cs

示例14: RunInValidTests

        /// <summary>
        /// Runs test for InValid cases
        /// </summary>
        /// <param name="nodeType">XElement/XAttribute</param>
        /// <param name="name">name to be tested</param>
        public void RunInValidTests(string nodeType, string name)
        {
            XDocument xDocument = new XDocument();
            XElement element = null;
            try
            {
                switch (nodeType)
                {
                    case "XElement":
                        element = new XElement(name, name);
                        xDocument.Add(element);
                        IEnumerable<XNode> nodeList = xDocument.Nodes();
                        break;
                    case "XAttribute":
                        element = new XElement(name, name);
                        XAttribute attribute = new XAttribute(name, name);
                        element.Add(attribute);
                        xDocument.Add(element);
                        XAttribute x = element.Attribute(name);
                        break;
                    case "XName":
                        XName xName = XName.Get(name, name);
                        break;
                    default:
                        break;
                }
            }
            catch (XmlException)
            {
                return;
            }
            catch (ArgumentException)
            {
                return;
            }

            Assert.True(false, "Expected exception not thrown");
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:43,代码来源:XLinqErrata4.cs

示例15: RunValidTests

 /// <summary>
 /// Runs test for valid cases
 /// </summary>
 /// <param name="nodeType">XElement/XAttribute</param>
 /// <param name="name">name to be tested</param>
 public void RunValidTests(string nodeType, string name)
 {
     XDocument xDocument = new XDocument();
     XElement element = null;
     switch (nodeType)
     {
         case "XElement":
             element = new XElement(name, name);
             xDocument.Add(element);
             IEnumerable<XNode> nodeList = xDocument.Nodes();
             Assert.True(nodeList.Count() == 1, "Failed to create element { " + name + " }");
             xDocument.RemoveNodes();
             break;
         case "XAttribute":
             element = new XElement(name, name);
             XAttribute attribute = new XAttribute(name, name);
             element.Add(attribute);
             xDocument.Add(element);
             XAttribute x = element.Attribute(name);
             Assert.Equal(name, x.Name.LocalName);
             xDocument.RemoveNodes();
             break;
         case "XName":
             XName xName = XName.Get(name, name);
             Assert.Equal(name, xName.LocalName);
             Assert.Equal(name, xName.NamespaceName);
             Assert.Equal(name, xName.Namespace.NamespaceName);
             break;
         default:
             break;
     }
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:37,代码来源:XLinqErrata4.cs


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