本文整理汇总了C#中XmlTextWriter.WriteStartDocument方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextWriter.WriteStartDocument方法的具体用法?C# XmlTextWriter.WriteStartDocument怎么用?C# XmlTextWriter.WriteStartDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlTextWriter
的用法示例。
在下文中一共展示了XmlTextWriter.WriteStartDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DumpArrayToXml
public void DumpArrayToXml ()
{
string metadata_filename = dir + Path.DirectorySeparatorChar + "album-data.xml";
XmlTextWriter writer = new XmlTextWriter (metadata_filename, Encoding.UTF8);
writer.WriteStartDocument (true);
writer.WriteStartElement ("album", "www.ximian.com");
writer.WriteAttributeString ("name", album_name);
writer.WriteAttributeString ("count", picture_count.ToString ());
for (int i = 0; i < picture_count; ++i) {
writer.WriteStartElement ("picture", "www.ximian.com");
writer.WriteElementString ("location", "www.ximian.com", picture_data [i].Location);
writer.WriteElementString ("title", "www.ximian.com", picture_data [i].Title);
writer.WriteElementString ("date", "www.ximian.com", picture_data [i].Date);
writer.WriteElementString ("keywords", "www.ximian.com", picture_data [i].Keywords);
writer.WriteElementString ("comments", "www.ximian.com", picture_data [i].Comments);
writer.WriteElementString ("index", "www.ximian.com", picture_data [i].Index.ToString ());
writer.WriteEndElement ();
}
writer.WriteEndElement ();
writer.WriteEndDocument ();
writer.Close ();
}
示例2: Main
static void Main()
{
using (var reader = new StreamReader(inputFile))
{
string line = reader.ReadLine();
if (line == null)
{
Console.WriteLine("The text file is empty");
return;
}
using (var writer = new XmlTextWriter(outputFile, Encoding.UTF8))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("People");
while (line != null)
{
var tokens = line.Split(';').Select(t => t.Trim()).ToArray();
WritePerson(writer, name: tokens[0], address: tokens[1], phone: tokens[2]);
line = reader.ReadLine();
}
writer.WriteEndDocument();
Console.WriteLine("XML file saved to {0}", outputFile);
}
}
}
示例3: BuildXMLString
private string BuildXMLString()
{
StringWriter str = new StringWriter();
XmlTextWriter xml = new XmlTextWriter(str);
// start doc and root el.
xml.WriteStartDocument();
xml.WriteStartElement("playerScoreList");
// data element
xml.WriteStartElement("player");
xml.WriteElementString("name", "matt");
xml.WriteElementString("score", "200");
xml.WriteEndElement();
// data element
xml.WriteStartElement("player");
xml.WriteElementString("name", "jane");
xml.WriteElementString("score", "150");
xml.WriteEndElement();
// end root and document
xml.WriteEndElement();
xml.WriteEndDocument();
return str.ToString();
}
示例4: GetRssFeedContens
private void GetRssFeedContens(AspxCommonInfo aspxCommonObj, string pageURL, int count)
{
try
{
string[] path = pageURL.Split('?');
string pagepath = path[0];
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/xml";
XmlTextWriter rssXml = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);
rssXml.WriteStartDocument();
rssXml.WriteStartElement("rss");
rssXml.WriteAttributeString("version", "2.0");
rssXml.WriteStartElement("channel");
rssXml.WriteElementString("link", pagepath);
rssXml.WriteElementString("title", getLocale("AspxCommerce Services"));
GetItemRssFeedContents(aspxCommonObj, rssXml, pageURL,count);
rssXml.WriteEndElement();
rssXml.WriteEndElement();
rssXml.WriteEndDocument();
rssXml.Flush();
rssXml.Close();
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
throw ex;
}
}
示例5: Main
static void Main()
{
using (var writer = new XmlTextWriter(filePath, encoding))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("catalogue");
writer.WriteAttributeString("name", "Awesome Mix Vol. 1");
WriteAlbum(writer, "Hooked on a Feeling", "Blue Swede", 1968, "Scepter Records", 20);
WriteAlbum(writer, "Record World", "Raspberries", 1972, "Capitol Records", 18.50m,
new List<string>() { "Don't Want to Say Goodbye", "Go All the Way", "I Wanna Be with You" });
WriteAlbum(writer, "Starting Over", "Raspberries", 1974, "Capitol", 17.50m);
WriteAlbum(writer, "Wovoka", "Redbone", 1974, "Lolly Vegas", 11,
new List<string>() { "Come and Get Your Love", "When You Got Trouble" });
WriteAlbum(writer, "The 5th Dimension", "Blue Swede", 1974, "Warner Bros.", 9.99m);
writer.WriteEndDocument();
}
Console.WriteLine("Document saved to {0}", filePath);
}
示例6: Main
/* 08. Write a program, which (using XmlReader and XmlWriter) reads the file catalog.xml
* and creates the file album.xml, in which stores in appropriate way
* the names of all albums and their authors.*/
static void Main(string[] args)
{
using (XmlReader reader = XmlReader.Create("../../catalog.xml"))
{
string fileName = "../../albums.xml";
Encoding encoding = Encoding.GetEncoding("windows-1251");
using (XmlTextWriter writer = new XmlTextWriter(fileName, encoding))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("albums");
var title = string.Empty;
var artist = string.Empty;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "name")
{
title = reader.ReadElementString();
}
else if (reader.Name == "artist")
{
artist = reader.ReadElementString();
WriteAlbum(writer, title, artist);
}
}
}
}
}
}
示例7: Main
static void Main()
{
XmlReader reader = XmlReader.Create("../../catalogue.xml");
using (reader)
{
StreamWriter textWriter = new StreamWriter("../../albums.xml", false, Encoding.GetEncoding("utf-8"));
XmlTextWriter writer = new XmlTextWriter(textWriter);
using (writer)
{
writer.WriteStartDocument();
writer.WriteStartElement("album-catalog");
while (reader.Read())
{
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "album"))
{
writer.WriteStartElement("album");
reader.ReadToDescendant("name");
writer.WriteElementString(reader.Name, reader.ReadInnerXml());
reader.ReadToNextSibling("artist");
writer.WriteElementString(reader.Name, reader.ReadInnerXml());
writer.WriteEndElement();
}
}
writer.WriteEndElement();
writer.WriteEndDocument();
}
}
}
示例8: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter objX = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
objX.WriteStartDocument();
objX.WriteStartElement("rss");
objX.WriteAttributeString("version", "2.0");
objX.WriteStartElement("channel");
objX.WriteElementString("title", drvvv.Plugins.GetTextToSite("Anglodeals", "francodeals", "zebradeals"));
objX.WriteElementString("link", "http://anglodeals.co.il/rss.aspx");
objX.WriteElementString("description", "At Deals we compile the best coupons from both English and Hebrew anf franch websites daily, translate what is needed and put them up on one user-friendly website.");
objX.WriteElementString("copyright", "(c) 2012, anglodeals. All rights reserved.");
//objX.WriteElementString("ttl", "5");
foreach (var x in drvvv.drvvvSettings.GetDataContextInstance().Coupons.Where(x => x.Active && x.EndDate >= DateTime.Now && x.TitleEn != null).OrderByDescending(x => x.ID).Take(30))
{
objX.WriteStartElement("item");
objX.WriteElementString("guid", x.ID.ToString());
objX.WriteElementString("title", drvvv.Plugins.GetTextToSite(x.TitleEn, x.TitleFr, x.TitleDefault));
objX.WriteElementString("image", (drvvv.Plugins.ReturnImgAddress(x.ImgName)).Replace("~/", drvvv.Plugins.GetTextToSite("http://anglodeals.co.il/", "http://francodeals.co.il/", "http://zebradeals.co.il/")));
objX.WriteElementString("description", drvvv.Plugins.GetTextToSite(x.SubjectEn, x.SubjectFr, x.SubjectDefault));
objX.WriteElementString("link", string.Format("http://{2}/CouponAddress.aspx?couponID={0}&SiteID={1}", x.ID, 6, drvvv.Plugins.GetTextToSite("anglodeals.co.il", "francodeals.co.il", "zebradeals.co.il")));
objX.WriteElementString("pubDate", string.Format("{0:R}", x.EndDate));
objX.WriteEndElement();
}
objX.WriteEndElement();
objX.WriteEndElement();
objX.WriteEndDocument();
objX.Flush();
objX.Close();
Response.End();
}
示例9: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("urlset");
writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
string siteUrl = Request.Url.Scheme + Uri.SchemeDelimiter + System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
if (!Request.Url.IsDefaultPort)
{
siteUrl += ":" + Request.Url.Port;
}
Menu menu = new Menu();
Utils.InitMenu(menu, false, false, false);
foreach (MenuItem item in menu.Items)
{
writer.WriteStartElement("url");
writer.WriteElementString("loc", siteUrl + item.NavigateUrl);
writer.WriteEndElement();
foreach (MenuItem childItem in item.ChildItems)
{
writer.WriteStartElement("url");
writer.WriteElementString("loc", siteUrl + childItem.NavigateUrl);
writer.WriteEndElement();
}
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
Response.End();
}
示例10: Main
public static void Main()
{
string pathToSourceFile = "../../../albums.xml";
string pathToTargetFile = "../../../album.xml";
Encoding encoding = Encoding.GetEncoding("windows-1251");
using (XmlReader reader = XmlReader.Create(pathToSourceFile))
{
using (XmlTextWriter writer = new XmlTextWriter(pathToTargetFile, encoding))
{
string name = "", artist = "";
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("albums");
while (reader.Read())
{
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "name"))
{
name = reader.ReadElementString();
}
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "artist"))
{
artist = reader.ReadElementString();
WriteAlbum(writer, name, artist);
}
}
writer.WriteEndDocument();
}
}
}
示例11: AddRequestXml
private void AddRequestXml(string url, HttpWebRequest req)
{
Stream stream = (Stream)req.GetRequestStream();
using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8))
{
writer.WriteStartDocument(true);
writer.WriteStartElement("methodCall");
writer.WriteElementString("methodName", "pingback.ping");
writer.WriteStartElement("params");
writer.WriteStartElement("param");
writer.WriteStartElement("value");
writer.WriteElementString("string", Blogsa.Url);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteStartElement("param");
writer.WriteStartElement("value");
writer.WriteElementString("string", url);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
}
}
示例12: Write
public static void Write()
{
XmlTextWriter writer = new XmlTextWriter(Console.Out);
writer.WriteStartDocument();
writer.WriteElementString("Hello", "Xml");
writer.WriteEndDocument();
writer.Close();
}
示例13: Create
void Create()
{
XmlTextWriter writer = new XmlTextWriter ("todo.xml", System.Text.Encoding.UTF8);
writer.WriteStartDocument ();
writer.WriteStartElement ("tasks");
writer.WriteEndElement ();
writer.Close ();
}
示例14: Create
/// <summary>
/// This method is used for creating a new employee information in XML file
/// </summary>
/// <param name="employee">employee object</param>
/// <returns>True - Success, False - Failure</returns>
public bool Create(BLAutot auto)
{
try
{
// Checking if the file exist
if (!File.Exists(strFileName))
{
// If file does not exist in the database path, create and store an empty Autot node
XmlTextWriter textWritter = new XmlTextWriter(strFileName, null);
textWritter.WriteStartDocument();
textWritter.WriteStartElement("Wanhatautot");
textWritter.WriteEndElement();
textWritter.Close();
}
// Create the XML document by loading the file
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(strFileName);
// Creating Auto node
XmlElement subNode = xmlDoc.CreateElement("Auto");
// Getting the maximum Id based on the XML data already stored
string strId = CommonMethods.GetMaxValue(xmlDoc, "Wanhatautot" + "/" + "Auto" + "/" + "aid").ToString();
// Adding Id column. Auto generated column
subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "aid", strId));
xmlDoc.DocumentElement.AppendChild(subNode);
subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "rekkari", auto.rekkari));
xmlDoc.DocumentElement.AppendChild(subNode);
subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "merkki", auto.merkki));
xmlDoc.DocumentElement.AppendChild(subNode);
subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "malli", auto.malli));
xmlDoc.DocumentElement.AppendChild(subNode);
subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "vm", auto.vm.ToString()));
xmlDoc.DocumentElement.AppendChild(subNode);
subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "myyntiHinta", auto.myyntiHinta.ToString()));
xmlDoc.DocumentElement.AppendChild(subNode);
subNode.AppendChild(CommonMethods.CreateXMLElement(xmlDoc, "sisaanOstoHinta", auto.sisaanOstoHinta.ToString()));
xmlDoc.DocumentElement.AppendChild(subNode);
// Saving the file after adding the new auto node
xmlDoc.Save(strFileName);
return true;
}
catch (Exception ex)
{
throw ex;
}
}
示例15: WriteXmlReport
public static void WriteXmlReport(IEnumerable<XmlReport> reports)
{
string fileName = "../../../Sales-by-Vendors-report.xml";
Encoding encoding = Encoding.GetEncoding("windows-1251");
using (XmlTextWriter writer = new XmlTextWriter(fileName, encoding))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("sales");
string vendorName = "";
bool isFirst = true;
foreach (var report in reports)
{
if (report.VendorName !=vendorName && isFirst == true)
{
writer.WriteStartElement("sale");
writer.WriteAttributeString("vendor", report.VendorName);
writer.WriteStartElement("summary");
writer.WriteAttributeString("date", string.Format("{0:d}", report.FromDate));
writer.WriteAttributeString("total-sum", report.Sum.ToString());
writer.WriteEndElement();
vendorName = report.VendorName;
isFirst = false;
}
else if (report.VendorName !=vendorName && isFirst == false)
{
writer.WriteEndElement();
writer.WriteStartElement("sale");
writer.WriteAttributeString("vendor", report.VendorName);
writer.WriteStartElement("summary");
writer.WriteAttributeString("date", string.Format("{0:d}", report.FromDate));
writer.WriteAttributeString("total-sum", report.Sum.ToString());
writer.WriteEndElement();
vendorName = report.VendorName;
}
else
{
writer.WriteStartElement("summary");
writer.WriteAttributeString("date", string.Format("{0:d}", report.FromDate));
writer.WriteAttributeString("total-sum", report.Sum.ToString());
writer.WriteEndElement();
}
}
writer.WriteEndElement();
writer.WriteEndDocument();
}
}