本文整理汇总了C#中System.Xml.Linq.XElement.WriteTo方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.WriteTo方法的具体用法?C# XElement.WriteTo怎么用?C# XElement.WriteTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.WriteTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static string Create(CasperJsTestsResults casperJsTestsResults)
{
XNamespace testRunNamespace =
XNamespace.Get("http://microsoft.com/schemas/VisualStudio/TeamTest/2010");
var xml = new XElement("TestRun",
new XAttribute("id", Guid.NewGuid().ToString()),
new XElement("ResultSummary",
new XAttribute("outcome", "Completed"),
new XElement("Counters",
new XAttribute("total", (casperJsTestsResults.PassedTests.Count + casperJsTestsResults.FailedTests.Count).ToString()),
new XAttribute("passed", casperJsTestsResults.PassedTests.Count.ToString()),
new XAttribute("failed", casperJsTestsResults.FailedTests.Count.ToString()))),
new XElement("TestDefinitions",
GetUnitTestsDefinitions(casperJsTestsResults)),
new XElement("TestEntries",
GetUnitTestsEntries(casperJsTestsResults)),
new XElement("Results",
GetUnitTestsResults(casperJsTestsResults))
);
var xDocument = new XDocument(xml);
xDocument.Root.Name = testRunNamespace + xDocument.Root.Name.LocalName;
using (var textWriter = new StringWriter())
{
using (XmlWriter xmlWriter = XmlWriter.Create(textWriter))
{
xml.WriteTo(xmlWriter);
}
return textWriter.ToString();
}
}
示例2: XmlTest
void XmlTest()
{
XElement root = new XElement ("root");
for (int i = 0; i < 3; i ++) {
XElement item = new XElement ("item");
item.Add (new XAttribute ("1item" + i.ToString (), i));
item.Add (new XAttribute ("2item" + i.ToString (), i));
item.Add (new XAttribute ("3item" + i.ToString (), i));
}
using (FileStream fs = new FileStream( Application.dataPath + "/test.xml",FileMode.Create)) {
XmlWriterSettings setting = new XmlWriterSettings ();
setting.Indent = true;
setting.IndentChars = "\t";
setting.NewLineChars = "\n";
setting.Encoding = Encoding.UTF8;
using (XmlWriter xw = XmlWriter.Create(fs, setting)) {
root.WriteTo (xw);
}
}
// using(FileStream fs = new FileStream( FILE_DIR + "/" + "ServerConfig/terrainEditorConfig.xml", FileMode.Create ) )
// {
// XmlWriterSettings setting = new XmlWriterSettings();
// setting.Indent = true;
// setting.IndentChars = "\t";
// setting.NewLineChars = "\n";
// setting.Encoding = Encoding.UTF8;
// using (XmlWriter xw = XmlWriter.Create(fs, setting))
// {
// root.WriteTo(xw);
// }
// }
// }
}
示例3: WriteElement
internal static void WriteElement(XmlWriter writer, XElement element)
{
if (WriteWholeNode(element))
{
// Write entire element in one gulp, to avoid eating needed spaces in <Run> elements.
element.WriteTo(writer);
}
else
{
writer.WriteStartElement(element.Name.LocalName);
foreach (var attribute in element.Attributes())
{
writer.WriteAttributeString(attribute.Name.LocalName, attribute.Value);
}
if (element.HasElements)
{
foreach (var childNode in element.Elements().ToArray())
{
// Recurse on down to the bottom.
WriteElement(writer, childNode);
childNode.Remove();
}
}
else
{
if (!string.IsNullOrEmpty(element.Value))
writer.WriteString(element.Value);
}
writer.WriteEndElement();
}
}
示例4: WriteTo
public static void WriteTo(Bundle bundle, XmlWriter writer, bool summary = false)
{
if (bundle == null) throw new ArgumentException("Bundle cannot be null");
var root = new XElement(BundleXmlParser.XATOMNS + BundleXmlParser.XATOM_FEED);
if (!String.IsNullOrWhiteSpace(bundle.Title)) root.Add(xmlCreateTitle(bundle.Title));
if (SerializationUtil.UriHasValue(bundle.Id)) root.Add(xmlCreateId(bundle.Id));
if (bundle.LastUpdated != null) root.Add(new XElement(BundleXmlParser.XATOMNS + BundleXmlParser.XATOM_UPDATED, bundle.LastUpdated));
if (!String.IsNullOrWhiteSpace(bundle.AuthorName))
root.Add(xmlCreateAuthor(bundle.AuthorName, bundle.AuthorUri));
if (bundle.TotalResults != null) root.Add(new XElement(BundleXmlParser.XOPENSEARCHNS + BundleXmlParser.XATOM_TOTALRESULTS, bundle.TotalResults));
if (bundle.Links != null)
{
foreach (var l in bundle.Links)
root.Add(xmlCreateLink(l.Rel, l.Uri));
}
if (bundle.Tags != null)
{
foreach (var tag in bundle.Tags)
root.Add(TagListSerializer.CreateTagCategoryPropertyXml(tag));
}
foreach (var entry in bundle.Entries)
root.Add(createEntry(entry, summary));
root.WriteTo(writer);
//var result = new XDocument(root);
//result.WriteTo(writer);
}
示例5: XElementToString
public static string XElementToString(XElement xml)
{
var sw = new StringWriterUTF8(CultureInfo.CurrentCulture);
var writer = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true, IndentChars = "\t", Encoding = Encoding.UTF8 });
xml.WriteTo(writer);
writer.Flush();
writer.Close();
return sw.ToString();
}
示例6: SaveXElementUsingXmlWriter
private string SaveXElementUsingXmlWriter(XElement elem, NamespaceHandling nsHandling)
{
StringWriter sw = new StringWriter();
using (XmlWriter w = XmlWriter.Create(sw, new XmlWriterSettings() { NamespaceHandling = nsHandling, OmitXmlDeclaration = true }))
{
elem.WriteTo(w);
}
sw.Dispose();
return sw.ToString();
}
示例7: Write
public void Write(Interaction interaction) {
var tree = new XElement("tape",
new XElement("interaction",
MapRequest(interaction.Request),
MapResponse(interaction.Response)
)
);
tree.WriteTo(writer);
}
示例8: WriteResponse
public async Task WriteResponse(XElement feed)
{
ResponseContentType = "application/atom+xml; type=feed; charset=utf-8";
MemoryStream stream = new MemoryStream();
XmlWriter writer = XmlWriter.Create(stream);
feed.WriteTo(writer);
writer.Flush();
byte[] data = stream.ToArray();
await WriteResponseAsync(data);
}
示例9: Write
// Private Methods
//======================================================================
private void Write(XmlWriter outputWriter)
{
outputWriter.WriteStartDocument();
XElement root = new XElement(Xmlns + "Image",
new XAttribute("TileSize", DefaultTileSize),
new XAttribute("Overlap", DefaultOverlap),
new XAttribute("Format", DefaultFormat),
new XElement(Xmlns + "Size",
new XAttribute("Width", m_size.Width),
new XAttribute("Height", m_size.Height)));
root.WriteTo(outputWriter);
}
示例10: Table
public virtual void Table(TextWriter writer)
{
var tab = new XElement("table"
, new XAttribute("id", "postGrid")
, new XAttribute("class", "list"));
var th = TableHeader();
tab.Add(th);
foreach (object row in ReadData())
tab.Add(row);
tab.WriteTo(XmlWriter.Create(writer));
}
示例11: OnProcessRecord
protected override void OnProcessRecord()
{
var netConfig = new XElement(
NetconfigNamespace + "NetworkConfiguration",
new XAttribute("xmlns", NetconfigNamespace.NamespaceName),
new XAttribute(XNamespace.Xmlns + "xsi", InstanceNamespace.NamespaceName),
new XElement(NetconfigNamespace + "VirtualNetworkConfiguration"));
var stream = new MemoryStream();
var writer1 = XmlWriter.Create(stream);
netConfig.WriteTo(writer1);
writer1.Flush();
stream.Seek(0L, SeekOrigin.Begin);
this.ExecuteClientActionInOCS(null, this.CommandRuntime.ToString(), s => this.Channel.SetNetworkConfiguration(s, stream));
}
示例12: Write
public static void Write()
{
var xmlConfig = new XElement("Jira",
new XElement("ServerUrl", ServerUrl),
new XElement("Username", Username),
new XElement("Password", Password));
using (var xmlWriter = XmlWriter.Create(JiraOutput.PrefsPathWithFileName, new XmlWriterSettings()
{
Indent = true,
IndentChars = " "
}))
{
xmlConfig.WriteTo(xmlWriter);
}
}
示例13: Main
static void Main(string[] args)
{
//Write XML 1.1 file
StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.Encoding = Encoding.UTF8;
xws.Indent = true;
//Disable character checking
xws.CheckCharacters = false;
System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb, xws);
//write your own header
xw.WriteProcessingInstruction("xml", "version='1.1'");
XElement doc = new XElement("root");
doc.Add(
new XElement("test",
new XAttribute("val", "\x03")));
//use WriteTo instead of Save
doc.WriteTo(xw);
xw.Close();
//Print XML contents to console
Console.WriteLine(sb.ToString());
//Read XML 1.1 file
TextReader tr = new StringReader(sb.ToString());
tr.ReadLine(); //skip Version number '1.1' is invalid. exception
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.CheckCharacters = false;
XmlReader xr = XmlReader.Create(tr, xrs);
var xmldoc = XElement.Load(xr);
foreach (var e in xmldoc.Elements())
{
Console.Write("Element: {0}", e.Name);
foreach (var a in e.Attributes())
Console.Write(" Attribute: {0}={1}", a.Name, a.Value);
Console.WriteLine();
}
}
示例14: ParseXml2String
protected string ParseXml2String(XElement doc)
{
using (StringWriter sw = new StringWriter())
{
XmlWriterSettings settings = new XmlWriterSettings();
{
settings.OmitXmlDeclaration = true;
using (XmlWriter writer = XmlWriter.Create(sw, settings))
{
if (doc != null)
{
doc.WriteTo(writer);
}
}
}
return sw.ToString();
}
}
示例15: SerializeXElement
// ReSharper restore SuggestBaseTypeForParameter
// ReSharper disable SuggestBaseTypeForParameter
private static string SerializeXElement(XElement element)
{
using (var stringWriter = new StringWriter())
{
var settings = new XmlWriterSettings
{
Indent = true,
IndentChars = "\t",
OmitXmlDeclaration = true,
};
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings))
{
element.WriteTo(xmlWriter);
xmlWriter.Flush();
return stringWriter.ToString();
}
}
}