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


C# XStreamingElement.Add方法代码示例

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


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

示例1: WriteXStreamingElementChildren

		public void WriteXStreamingElementChildren ()
		{
			var xml = "<?xml version='1.0' encoding='utf-8'?><root type='array'><item type='number'>0</item><item type='number'>2</item><item type='number'>5</item></root>".Replace ('\'', '"');
			
			var ms = new MemoryStream ();
			var xw = XmlWriter.Create (ms);
			int [] arr = new int [] {0, 2, 5};
			var xe = new XStreamingElement (XName.Get ("root"));
			xe.Add (new XAttribute (XName.Get ("type"), "array"));
			var at = new XAttribute (XName.Get ("type"), "number");
			foreach (var i in arr)
				xe.Add (new XStreamingElement (XName.Get ("item"), at, i));

			xe.WriteTo (xw);
			xw.Close ();
			Assert.AreEqual (xml, new StreamReader (new MemoryStream (ms.ToArray ())).ReadToEnd (), "#1");
		}
开发者ID:nobled,项目名称:mono,代码行数:17,代码来源:XStreamingElementTest.cs

示例2: AddAttributeAfterContent

 public void AddAttributeAfterContent()
 {
     XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134");
     XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134");
     streamElement.Add(contact.Attribute("type"));
     using (XmlWriter w = XmlWriter.Create(new MemoryStream(), null))
     {
         Assert.Throws<InvalidOperationException>(() => streamElement.WriteTo(w));
     }
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:StreamingOutput.cs

示例3: AddAttribute

 public void AddAttribute()
 {
     XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134");
     XStreamingElement streamElement = new XStreamingElement("phone");
     streamElement.Add(contact.Attribute("type"));
     streamElement.Add("925-555-0134");
     GetFreshStream();
     streamElement.Save(_sourceStream);
     contact.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:StreamingOutput.cs

示例4: AddTimeSpanObject

 public void AddTimeSpanObject()
 {
     XElement contact = new XElement("Time", TimeSpan.FromMinutes(12));
     XStreamingElement streamElement = new XStreamingElement("Time");
     streamElement.Add(TimeSpan.FromMinutes(12));
     GetFreshStream();
     streamElement.Save(_sourceStream);
     contact.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:11,代码来源:StreamingOutput.cs

示例5: AddObject

 public void AddObject(object content)
 {
     XElement contact = new XElement("phone", content);
     XStreamingElement streamElement = new XStreamingElement("phone");
     streamElement.Add(content);
     GetFreshStream();
     streamElement.Save(_sourceStream);
     contact.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:11,代码来源:StreamingOutput.cs

示例6: AddWithNull

 //[Variation(Priority = 1, Desc = "Add(null)")]
 public void AddWithNull()
 {
     XStreamingElement streamElement = new XStreamingElement("contact");
     streamElement.Add(null);
     if (!streamElement.ToString().Equals("<contact />"))
         throw new TestFailedException("");
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:8,代码来源:StreamingOutput.cs

示例7: SaveLow

        private static void SaveLow(Dictionary<string, object> paraDic)
        {
            try
            {
                //新建一个xml文档类
                XDocument xdoc = new XDocument();
                //可以增加注释
                xdoc.Add(new XComment("增加注释测试"));
                //增加内容
                XStreamingElement rootXE = new XStreamingElement("root");

                Jewelry je = paraDic["context"] as Jewelry;

                //解析内容
                rootXE.Add(new XElement("guid", je.Guid.ToString()));
                rootXE.Add(new XElement("image", helper.ImageToBase64(je.Image)));
                rootXE.Add(new XElement("totalweight", je.TotalWeight.ToString()));
                rootXE.Add(new XElement("jadeweight", je.JadeWeight.ToString()));
                rootXE.Add(new XElement("goldweight", je.GoldWeight.ToString()));
                rootXE.Add(new XElement("processfee", je.ProcessFee.ToString()));
                rootXE.Add(new XElement("otherfee", je.OtherFee.ToString()));
                rootXE.Add(new XElement("totalprice", je.TotalPrice.ToString()));

                xdoc.Add(rootXE);

                string sql = string.Format("insert into {0} Values('{1}','{2}','{3}','{4}')", "detail", je.Guid.ToString(), xdoc.ToString(), System.DateTime.Now, System.DateTime.Now);

                SQLiteConnection conn = new SQLiteConnection(@"Data Source=c:/xhz/ms.db;");
                //SQLiteConnection conn = new SQLiteConnection(@"Data Source=DB/ms.db;");
                conn.Open();
                SQLiteCommand cmd = new SQLiteCommand(sql, conn);

                int i = cmd.ExecuteNonQuery();

                System.Windows.MessageBox.Show(i.ToString());

                conn.Close();

            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message.ToString());
            }
            finally
            {

            }
        }
开发者ID:haozhouxu,项目名称:Jewelry,代码行数:48,代码来源:CommandCenter.cs

示例8: AddIEnumerableOfXNodesPlusAttribute

 public void AddIEnumerableOfXNodesPlusAttribute()
 {
     InputSpace.Contacts(ref _xDoc, ref _xmlDoc);
     XAttribute xAttrib = new XAttribute("Attribute", "Value");
     XElement element = new XElement("contacts", xAttrib, _xDoc.Root.DescendantNodes());
     XStreamingElement streamElement = new XStreamingElement("contacts");
     streamElement.Add(xAttrib, _xDoc.Root.DescendantNodes());
     GetFreshStream();
     streamElement.Save(_sourceStream);
     element.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:13,代码来源:StreamingOutput.cs

示例9: AddIEnumerableOfMixedNodes

 //[Variation(Priority = 1, Desc = "Add(IEnumerable of Mixed Nodes)")]
 public void AddIEnumerableOfMixedNodes()
 {
     XElement element = new XElement("root", GetMixedNodes());
     XStreamingElement streamElement = new XStreamingElement("root");
     streamElement.Add(GetMixedNodes());
     getFreshStream();
     streamElement.Save(_sourceStream); element.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:12,代码来源:StreamingOutput.cs

示例10: AddIEnumerableOfXNodes

 //[Variation(Priority = 0, Desc = "Add(IEnumerable of XNodes)")]
 public void AddIEnumerableOfXNodes()
 {
     XElement x = InputSpace.GetElement(100, 3);
     XElement element = new XElement("root", x.Nodes());
     XStreamingElement streamElement = new XStreamingElement("root");
     streamElement.Add(x.Nodes());
     getFreshStream();
     streamElement.Save(_sourceStream); element.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:13,代码来源:StreamingOutput.cs

示例11: AddAttributeAfterContent

 //An attribute cannot be written after content.
 //[Variation(Priority = 1, Desc = "Add(XAttribute) After Content is Added)")]
 public void AddAttributeAfterContent()
 {
     try
     {
         XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134");
         XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134");
         streamElement.Add(contact.Attribute("type"));
         using (XmlWriter w = XmlWriter.Create(new MemoryStream(), null))
         {
             streamElement.WriteTo(w);
         }
     }
     catch (System.InvalidOperationException)
     {
         return;
     }
     throw new TestFailedException("");
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:20,代码来源:StreamingOutput.cs

示例12: AddAttribute

 //[Variation(Priority = 0, Desc = "Add(XAttribute)")]
 public void AddAttribute()
 {
     XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134");
     XStreamingElement streamElement = new XStreamingElement("phone");
     streamElement.Add(contact.Attribute("type"));
     streamElement.Add("925-555-0134");
     getFreshStream();
     streamElement.Save(_sourceStream); contact.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:13,代码来源:StreamingOutput.cs

示例13: AddTimeSpanObject

 //[Variation(Priority = 1, Desc = "Add(TimeSpan)")]
 public void AddTimeSpanObject()
 {
     XElement contact = new XElement("Time", TimeSpan.FromMinutes(12));
     XStreamingElement streamElement = new XStreamingElement("Time");
     streamElement.Add(TimeSpan.FromMinutes(12));
     getFreshStream();
     streamElement.Save(_sourceStream); contact.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:12,代码来源:StreamingOutput.cs

示例14: AddObject

 //[Variation(Priority = 0, Desc = "Add(String)", Params = new object[] { "9255550134" })]
 //[Variation(Priority = 0, Desc = "Add(Double)", Params = new object[] { (Double)9255550134 })]
 //[Variation(Priority = 0, Desc = "Add(Int)", Params = new object[] { (Int64)9255550134 })]
 public void AddObject()
 {
     XElement contact = new XElement("phone", Variation.Params[0]);
     XStreamingElement streamElement = new XStreamingElement("phone");
     streamElement.Add(Variation.Params[0]);
     getFreshStream();
     streamElement.Save(_sourceStream); contact.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:14,代码来源:StreamingOutput.cs

示例15: AddIEnumerableOfXNodes

 public void AddIEnumerableOfXNodes()
 {
     XElement x = InputSpace.GetElement(100, 3);
     XElement element = new XElement("root", x.Nodes());
     XStreamingElement streamElement = new XStreamingElement("root");
     streamElement.Add(x.Nodes());
     GetFreshStream();
     streamElement.Save(_sourceStream);
     element.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:StreamingOutput.cs


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