本文整理汇总了C#中System.Xml.Linq.XDocument.CreateWriter方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.CreateWriter方法的具体用法?C# XDocument.CreateWriter怎么用?C# XDocument.CreateWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.CreateWriter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransformXML
public static XDocument TransformXML(XDocument doc, string xslPath)
{
XDocument newdoc = new XDocument();
using (XmlWriter writer = newdoc.CreateWriter())
{
// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XmlReader.Create(xslPath));
// Execute the transform and output the results to a writer.
xslt.Transform(doc.CreateReader(), writer);
}
return newdoc;
/*
XslCompiledTransform transform = new XslCompiledTransform();
using (XmlReader reader = XmlReader.Create(xslPath))
{
transform.Load(reader);
}
StringWriter results = new StringWriter();
transform.Transform(doc, null, results);
var newdoc = new XmlDocument();
newdoc.LoadXml(results.ToString());
return newdoc;
* */
}
示例2: GeneratePlainReport_1
public void GeneratePlainReport_1()
{
ReportModel model = ReportModel.Create();
ReportStructure reportStructure = new ReportStructure()
{
ReportLayout = GlobalEnums.ReportLayout.ListLayout
};
IReportGenerator generator = new GeneratePlainReport(model,reportStructure);
generator.GenerateReport();
XDocument doc1 = XDocument.Load(new XmlNodeReader (generator.XmlReport));
XDocument doc2 = new XDocument();
using (XmlWriter w = doc2.CreateWriter()){
generator.XmlReport.Save (w);
}
XDocument doc3 = ReportGenerationHelper.XmlDocumentToXDocument(generator.XmlReport);
Assert.IsNotNull (doc1);
Assert.IsNotNull (doc2);
Assert.IsNotNull (doc2);
var sq = from si in doc1.Descendants() select si;
Console.WriteLine ("xxxxx");
foreach (XElement a in sq)
{
Console.WriteLine (a.Name);
}
}
示例3: GetXElement
/// <summary>
/// Pulled from http://blogs.msdn.com/b/ericwhite/archive/2008/12/22/convert-xelement-to-xmlnode-and-convert-xmlnode-to-xelement.aspx
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
internal static XElement GetXElement(this XmlNode node)
{
XDocument xDoc = new XDocument();
using (XmlWriter xmlWriter = xDoc.CreateWriter())
node.WriteTo(xmlWriter);
return xDoc.Root;
}
示例4: SerializeConfig
private void SerializeConfig()
{
var extraTypes = new Type[1]{typeof(AbstractConsumer)};
XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);
using(var writer = doc.CreateWriter())
{
new XmlSerializer(typeof(configuration), extraTypes).Serialize(writer, config, namespaces);
}
doc.Element("configuration").Add(
new XElement("controllers",
new XElement("tcp",
new XElement[2]
{
new XElement("port", 5250),
new XElement("protocol", "AMCP")
})));
doc.Add(new XComment(CasparCGConfigurator.Properties.Resources.configdoc.ToString()));
using (var writer = new XmlTextWriter("casparcg.config", new UTF8Encoding(false, false))) // No BOM
{
writer.Formatting = Formatting.Indented;
doc.Save(writer);
}
}
示例5: CreateNuspecGraph
public static IGraph CreateNuspecGraph(XDocument nuspec, string baseAddress)
{
nuspec = NormalizeNuspecNamespace(nuspec);
XslCompiledTransform transform = CreateTransform("xslt.nuspec.xslt");
XsltArgumentList arguments = new XsltArgumentList();
arguments.AddParam("base", "", baseAddress + "packages/");
arguments.AddParam("extension", "", ".json");
arguments.AddExtensionObject("urn:helper", new XsltHelper());
XDocument rdfxml = new XDocument();
using (XmlWriter writer = rdfxml.CreateWriter())
{
transform.Transform(nuspec.CreateReader(), arguments, writer);
}
RdfXmlParser rdfXmlParser = new RdfXmlParser();
XmlDocument doc = new XmlDocument();
doc.Load(rdfxml.CreateReader());
IGraph graph = new Graph();
rdfXmlParser.Load(graph, doc);
return graph;
}
示例6: GetXElement
/// <summary>
/// Provides an extension method that converts an
/// XmlNode to a Linq XElement.
/// </summary>
/// <param name="node">the XmlNode</param>
/// <returns>Linq XElement</returns>
public static XElement GetXElement(this XmlNode node)
{
var xDoc = new XDocument();
using (var xmlWriter = xDoc.CreateWriter())
node.WriteTo(xmlWriter);
return xDoc.Root;
}
示例7: GetXElement
private static XElement GetXElement(XmlNode node) {
var xDoc = new XDocument();
using (XmlWriter xmlWriter = xDoc.CreateWriter()) {
node.WriteTo(xmlWriter);
}
return xDoc.Root;
}
示例8: GetXElement
private XElement GetXElement(XmlNode node)
{
XDocument xDoc = new XDocument();
using (XmlWriter xmlWriter = xDoc.CreateWriter())
node.WriteTo(xmlWriter);
return xDoc.Root;
}
示例9: SendBodyAsync
protected override async Task SendBodyAsync(IRequestContext context)
{
if (Xslt != null) {
if (Model is XDocument)
await TransformAsync(context, ((XDocument)Model).CreateNavigator());
else if (Model is IXPathNavigable)
await TransformAsync(context, ((IXPathNavigable)Model));
else {
var ser = Serializer ?? new XmlSerializer(Model.GetType());
var doc = new XDocument();
using (var writer = doc.CreateWriter())
ser.Serialize(writer, Model);
await TransformAsync(context, doc.CreateNavigator());
}
}
else {
using (var writer = context.Response.GetStreamWriter()) {
if (Model is XDocument)
((XDocument)Model).Save(writer);
else if (Model is XmlDocument)
((XmlDocument)Model).Save(writer);
else if (Model is IXPathNavigable)
using (var xWriter = new XmlTextWriter(writer))
((IXPathNavigable)Model).CreateNavigator().WriteSubtree(xWriter);
else
(Serializer ?? new XmlSerializer(Model.GetType()))
.Serialize(writer, Model);
}
}
}
示例10: Initialize
public override void Initialize()
{
base.Initialize();
List<Notice> list = new List<Notice>();
list.Add(new Notice() { Year = 1972, News = "PLATO IV: First computer with \n a touchable screen." });
list.Add(new Notice() { Year = 1985, News = "Home Manager: First home computer \n with a touchable screen." });
list.Add(new Notice() { Year = 1992, News = "SIMON. First smartphone." });
list.Add(new Notice() { Year = 1999, News = "Edge: Voting machine." });
list.Add(new Notice() { Year = 2000, News = "iPhone: Firts multitouch smartphone." });
XDocument doc = new XDocument();
XmlSerializer serializer = new XmlSerializer(typeof(List<Notice>));
System.Xml.XmlWriter writer = doc.CreateWriter();
serializer.Serialize(writer, list);
writer.Close();
IsolatedStorage.SaveFile(doc, "myFile");
btGetNotice = new Button("Get next notice");
btGetNotice.Released += new Component.ComponentEventHandler(btnOpenBox_Released);
AddComponent(btGetNotice, 50, 600);
lblTime = new Label(list[0].Year.ToString());
lblNotice = new Label(list[0].News);
AddComponent(lblTime, 50, 100);
AddComponent(lblNotice, 50, 200);
index = 1;
}
示例11: Serialize
/// <summary>
/// Serializes the specified ParticleEffect instance.
/// </summary>
/// <param name="effect">The ParticleEffect to be serialized.</param>
/// <param name="filename">The desired output file name,</param>
public void Serialize(ParticleEffect effect, string filename)
{
// Create a new xml document...
XDocument xmlDocument = new XDocument();
// Use the XNA serializer to populate the xml document...
using (XmlWriter writer = xmlDocument.CreateWriter())
{
IntermediateSerializer.Serialize<ParticleEffect>(writer, effect, ".\\");
}
//// hack: Workaround for intermediate serializer not putting nodes in the right order...
//foreach (XElement emitterElement in xmlDocument.Descendants("Asset").Elements("Item"))
//{
// XElement releaseQuantityElement = emitterElement.Element("ReleaseQuantity");
// if ((releaseQuantityElement.PreviousNode as XElement).Name == "Name")
// {
// XElement termElement = emitterElement.Element("Term");
// termElement.AddAfterSelf(releaseQuantityElement);
// releaseQuantityElement.Remove();
// }
//}
// Save the xml document...
xmlDocument.Save(filename);
}
示例12: ReadWrite
public void ReadWrite()
{
var person = new Person() { Name = "duraid", Age = 35 };
person.Addresses.Add(new Address() { Street = "Decelles", City = "Montreal" });
person.Addresses.Add(new Address() { Street = "Lincoln", City = "Montreal" });
var map = new PersonMap();
var doc = new XDocument();
using (var writer = doc.CreateWriter())
{
map.WriteXml(writer, person);
}
Person person2;
using (var reader = doc.CreateReader())
{
person2 = map.ReadXml(reader);
}
Assert.AreEqual(person.Name, person2.Name);
Assert.AreEqual(person.Age, person2.Age);
Assert.AreEqual(2, person.Addresses.Count);
person.Addresses.Where(a => a.Street == "Decelles" && a.City == "Montreal").Single();
person.Addresses.Where(a => a.Street == "Lincoln" && a.City == "Montreal").Single();
}
示例13: GetPersonInfo
public Stream GetPersonInfo(string id)
{
int personId = 0;
int.TryParse(id, out personId);
Person personFound = persons.FirstOrDefault(p => p.Id == personId);
if (WebOperationContext.Current != null)
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
var reader = new StringReader(Resource.Style);
XmlReader xreader = XmlReader.Create(reader);
var xslt = new XslCompiledTransform(false);
xslt.Load(xreader);
var serializer = new XmlSerializer(typeof(Person));
var doc = new XDocument();
using (XmlWriter writer = doc.CreateWriter())
{
if (personFound != null)
serializer.Serialize(writer, personFound);
}
var outputWriter = new StringWriter();
xslt.Transform(doc.CreateNavigator(), null, outputWriter);
string htmlEmailText = outputWriter.ToString();
var encoding = new System.Text.ASCIIEncoding();
var stream = new MemoryStream(encoding.GetBytes(htmlEmailText));
return stream;
}
示例14: PerformAnotherWordGrammarDebuggerStepPage
/// <summary>
/// Perform another step in the word grammar debugging process and
/// produce an html page showing the results
/// </summary>
/// <param name="nodeId">Id of the selected node to use</param>
/// <param name="form"></param>
/// <param name="lastUrl"></param>
/// <returns>temporary html file showing the results of the next step</returns>
public string PerformAnotherWordGrammarDebuggerStepPage(string nodeId, string form, string lastUrl)
{
m_xmlHtmlStack.Push(Tuple.Create(m_wordGrammarDebuggerXml, lastUrl));
var doc = new XDocument();
using (XmlWriter writer = doc.CreateWriter())
CreateSelectedWordGrammarXml(writer, nodeId, form);
return CreateWordDebuggerPage(doc);
}
示例15: SetUpWordGrammarDebuggerPage
/// <summary>
/// Initialize what is needed to perform the word grammar debugging and
/// produce an html page showing the results
/// </summary>
/// <param name="nodeId">Id of the node to use</param>
/// <param name="form">the wordform being tried</param>
/// <param name="lastUrl"></param>
/// <returns>temporary html file showing the results of the first step</returns>
public string SetUpWordGrammarDebuggerPage(string nodeId, string form, string lastUrl)
{
m_xmlHtmlStack.Push(Tuple.Create((XDocument) null, lastUrl));
var doc = new XDocument();
using (XmlWriter writer = doc.CreateWriter())
CreateAnalysisXml(writer, nodeId, form);
return CreateWordDebuggerPage(doc);
}