本文整理汇总了C#中System.Xml.Linq.XStreamingElement类的典型用法代码示例。如果您正苦于以下问题:C# XStreamingElement类的具体用法?C# XStreamingElement怎么用?C# XStreamingElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XStreamingElement类属于System.Xml.Linq命名空间,在下文中一共展示了XStreamingElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: XElement
public XElement (XStreamingElement other)
{
if (other == null)
throw new ArgumentNullException ("other");
this.name = other.Name;
Add (other.Contents);
}
示例2: WriteFile
private void WriteFile(string targetDirectory, string entityNames, XStreamingElement fileContents)
{
var fileContentsWithHeader = @"<?xml version=""1.0"" encoding=""utf-8""?>" + Environment.NewLine + fileContents;
var path = Path.Combine(targetDirectory, entityNames + ".xml");
if (File.Exists(path))
{
var existingFileContents = File.ReadAllText(path);
if (existingFileContents == fileContentsWithHeader)
{
return;
}
var backupFolder = Path.Combine(targetDirectory, @"backup\");
Directory.CreateDirectory(backupFolder);
var fileNumber = GetFileNumber(backupFolder, entityNames);
var backupFileName = String.Format("{0}.backup-{1}.xml", entityNames, fileNumber);
var backupPath = Path.Combine(backupFolder, backupFileName);
File.Move(path, backupPath);
}
File.WriteAllText(path, fileContentsWithHeader);
}
示例3: ToStringAttributeAfterText
public void ToStringAttributeAfterText ()
{
var el = new XStreamingElement ("foo",
"text",
new XAttribute ("bar", "baz"));
el.ToString ();
}
示例4: ToString
public void ToString ()
{
var el = new XStreamingElement ("foo",
new XAttribute ("bar", "baz"),
"text");
Assert.AreEqual ("<foo bar=\"baz\">text</foo>", el.ToString ());
}
示例5: XNameWithNamespaceConstructor
public void XNameWithNamespaceConstructor()
{
XNamespace ns = @"http:\\www.contacts.com\";
XElement contact = new XElement(ns + "contact");
XStreamingElement streamElement = new XStreamingElement(ns + "contact");
GetFreshStream();
streamElement.Save(_sourceStream);
contact.Save(_targetStream);
ResetStreamPos();
Assert.True(Diff.Compare(_sourceStream, _targetStream));
}
示例6: XNameAsEmptyStringConstructor
//[Variation(Priority = 1, Desc = "Constructor - XStreamingElement('')")]
public void XNameAsEmptyStringConstructor()
{
try
{
XStreamingElement streamElement = new XStreamingElement(" ");
}
catch (System.Xml.XmlException)
{
return;
}
throw new TestFailedException("");
}
示例7: XNameAsNullConstructor
//[Variation(Priority = 1, Desc = "Constructor - XStreamingElement(null)")]
public void XNameAsNullConstructor()
{
try
{
XStreamingElement streamElement = new XStreamingElement(null);
}
catch (System.ArgumentNullException)
{
return;
}
throw new TestFailedException("");
}
示例8: 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");
}
示例9: WriteAccounts_creates_a_backup_and_overwrites_Account_file_if_it_has_changed
public void WriteAccounts_creates_a_backup_and_overwrites_Account_file_if_it_has_changed()
{
_fileWriter.WriteAccountFile(TestDirectory);
var originalTimestamp = File.GetLastWriteTimeUtc(_expectedAccountPath);
Thread.Sleep(10);
var modifiedAccountXml = new XStreamingElement("test", "someDifferentContent");
_accountRepository.EmitXml().Returns(modifiedAccountXml);
_fileWriter.WriteAccountFile(TestDirectory);
var timestampAfterSecondWrite = File.GetLastWriteTimeUtc(_expectedAccountPath);
Assert.AreNotEqual(originalTimestamp, timestampAfterSecondWrite);
var backupPath = Path.Combine(TestDirectory, @"backup\", "accounts.backup-1.xml");
Assert.IsTrue(File.Exists(backupPath));
Assert.AreEqual(_accountXml.ToString(), File.ReadAllText(backupPath));
Assert.AreEqual(originalTimestamp, File.GetLastWriteTimeUtc(backupPath));
}
示例10: WriteStreamingElement
internal void WriteStreamingElement(XStreamingElement e)
{
FlushElement();
_element = e;
Write(e.content);
bool contentWritten = _element == null;
FlushElement();
if (contentWritten)
{
_writer.WriteFullEndElement();
}
else
{
_writer.WriteEndElement();
}
_resolver.PopScope();
}
示例11: XNameAndNullObjectConstructor
public void XNameAndNullObjectConstructor()
{
XStreamingElement streamElement = new XStreamingElement("contact", null);
Assert.Equal("<contact />", streamElement.ToString());
}
示例12: XElement
public XElement (XStreamingElement other)
{
this.name = other.Name;
Add (other.Contents);
}
示例13: XNameAndXElementObjectConstructor
public void XNameAndXElementObjectConstructor()
{
XElement contact = new XElement("contact", new XElement("phone", "925-555-0134"));
XStreamingElement streamElement = new XStreamingElement("contact", contact.Element("phone"));
GetFreshStream();
streamElement.Save(_sourceStream);
contact.Save(_targetStream);
ResetStreamPos();
Assert.True(Diff.Compare(_sourceStream, _targetStream));
}
示例14: XStreamingElementSave_SaveOptions
public void XStreamingElementSave_SaveOptions()
{
string markup = "<e a=\"value\"> <!--comment--> <e2> <![CDATA[cdata]]> </e2> <?pi target?> </e>";
try
{
XElement e = XElement.Parse(markup, LoadOptions.PreserveWhitespace);
XStreamingElement e2 = new XStreamingElement(e.Name, e.Attributes(), e.Nodes());
e2.Save(_fileName, SaveOptions.DisableFormatting);
}
finally
{
Assert.True(File.Exists(_fileName));
Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + markup, File.ReadAllText(_fileName));
File.Delete(_fileName);
}
}
示例15: MakeItems
private XStreamingElement MakeItems()
{
XStreamingElement items = new XStreamingElement(Xmlns + "Items", MakeItemsContent());
return items;
}