本文整理汇总了C#中XmlTextWriter.WriteElementString方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextWriter.WriteElementString方法的具体用法?C# XmlTextWriter.WriteElementString怎么用?C# XmlTextWriter.WriteElementString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlTextWriter
的用法示例。
在下文中一共展示了XmlTextWriter.WriteElementString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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;
}
}
示例3: WriteBookmarks
private static void WriteBookmarks(
XmlTextWriter writer, IList<Bookmark> bookmarks)
{
writer.WriteStartElement("result-set");
foreach (var bookmark in bookmarks)
{
writer.WriteStartElement("bookmark");
if (bookmark.User.Username != null)
{
writer.WriteElementString("username", bookmark.User.Username);
}
if (bookmark.Title != null)
{
writer.WriteElementString("title", bookmark.Title);
}
if (bookmark.URL != null)
{
writer.WriteElementString("url", bookmark.URL);
}
if (bookmark.Tags.Count > 0)
{
string tags = string.Join(", ",
bookmark.Tags.Select(t => t.Name).OrderBy(t => t));
writer.WriteElementString("tags", tags);
}
if (bookmark.Notes != null)
{
writer.WriteElementString("notes", bookmark.Notes);
}
writer.WriteEndElement();
}
writer.WriteEndElement();
}
示例4: AddURL
private void AddURL(XmlTextWriter writer, string siteUrl, string url, DateTime dateUpdate)
{
writer.WriteStartElement("url");
writer.WriteElementString("loc", siteUrl + url);
writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", dateUpdate));
writer.WriteEndElement();
}
示例5: 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();
}
}
示例6: 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();
}
}
}
示例7: 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();
}
示例8: WriteAlbum
private static void WriteAlbum(XmlTextWriter writer, string name, string artist)
{
writer.WriteStartElement("album");
writer.WriteElementString("name", name);
writer.WriteElementString("artist", artist);
writer.WriteEndElement();
}
示例9: PrintReviews
public static void PrintReviews(XmlTextWriter writer, IList<Review> reviews)
{
writer.WriteStartElement("result-set");
foreach (var review in reviews)
{
writer.WriteStartElement("review");
string dateStr = review.Date.ToString(
Constants.DATE_FORMAT, Constants.DEFAULT_CULTURE);
writer.WriteElementString("date", dateStr);
writer.WriteElementString("content", review.Content);
Book book = review.Book;
writer.WriteStartElement("book");
writer.WriteElementString("title", book.Title);
if (book.Authors.Count > 0)
{
string bookAuthors = string.Join(", ",
book.Authors.OrderBy(a => a.Name).Select(a => a.Name));
writer.WriteElementString("authors", bookAuthors);
}
if (book.ISBN != null)
{
writer.WriteElementString("isbn", book.ISBN);
}
if (book.Url != null)
{
writer.WriteElementString("url", book.Url);
}
writer.WriteEndElement();
writer.WriteEndElement();
}
writer.WriteEndElement();
}
示例10: TreverseDirectories
private static void TreverseDirectories(XmlTextWriter writer, DirectoryInfo dir)
{
var folders = dir.GetDirectories();
var files = dir.GetFiles();
writer.WriteStartElement("folder");
writer.WriteElementString("name", dir.Name);
try
{
if (files.Count() > 0)
{
writer.WriteStartElement("files");
foreach (var file in files)
{
writer.WriteElementString("name", file.Name);
}
writer.WriteEndElement();
}
foreach (var child in folders)
{
TreverseDirectories(writer, child);
}
writer.WriteEndElement();
}
catch (Exception)
{
Console.WriteLine("Access denied! ");
}
}
示例11: 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();
}
示例12: ObjectToElement
private void ObjectToElement(XmlTextWriter xml)
{
// data element
xml.WriteStartElement("player");
xml.WriteElementString("name", _name);
string scoreString = "" + _score; // make _score a string
xml.WriteElementString("score", scoreString);
xml.WriteEndElement();
}
示例13: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetNoStore();
Response.ContentType = "application/xml";
DataTable dt = CreateBll.GetInfo(TABLE_NAME, 1, 100);
MemoryStream ms = new MemoryStream();
XmlTextWriter xmlTW = new XmlTextWriter(ms, Encoding.UTF8);
xmlTW.Formatting = Formatting.Indented;
xmlTW.WriteStartDocument();
xmlTW.WriteStartElement("urlset");
xmlTW.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
xmlTW.WriteAttributeString("xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9");
foreach (DataRow dr in dt.Rows)
{
xmlTW.WriteStartElement("url");
string infoUrl = CreateBll.GetInfoUrl(dr,1).ToLower();
if(!infoUrl.StartsWith("http://")&&!infoUrl.StartsWith("https://")&&!infoUrl.StartsWith("ftp://"))
{
if(Param.ApplicationRootPath==string.Empty)
{
infoUrl = CreateBll.SiteModel.Domain+infoUrl;
}
else
{
infoUrl = infoUrl.Replace(Param.ApplicationRootPath.ToLower(),string.Empty);
infoUrl = CreateBll.SiteModel.Domain+infoUrl;
}
}
xmlTW.WriteElementString("loc", infoUrl);
xmlTW.WriteStartElement("news:news");
xmlTW.WriteElementString("news:publication_date", dr["addtime"].ToString());
string keywords = dr["tagnamestr"].ToString();
if (keywords.StartsWith("|") && keywords.EndsWith("|"))
{
keywords = keywords.Substring(0, keywords.Length - 1);
keywords = keywords.Substring(1, keywords.Length - 1);
keywords = keywords.Replace("|",",");
}
xmlTW.WriteElementString("news:keywords", keywords);
xmlTW.WriteEndElement();
xmlTW.WriteEndElement();
}
xmlTW.WriteEndDocument();
xmlTW.Flush();
byte[] buffer = ms.ToArray();
Response.Write(Encoding.UTF8.GetString(buffer));
Response.End();
xmlTW.Close();
ms.Close();
ms.Dispose();
}
示例14: Write
public static void Write()
{
XmlTextWriter writer = new XmlTextWriter(Console.Out);
writer.WriteStartDocument();
writer.WriteElementString("Hello", "Xml");
writer.WriteEndDocument();
writer.Close();
}
示例15: Main
static void Main()
{
using (var reader = XmlReader.Create(inputFile))
{
using (var writer = new XmlTextWriter(outputFile, Encoding.UTF8))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("albums");
bool openAlbum = false;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "album")
{
if (openAlbum)
{
writer.WriteEndElement();
}
openAlbum = true;
writer.WriteStartElement("album");
}
else if (reader.Name == "name")
{
writer.WriteElementString("name", reader.ReadElementString());
}
else if (reader.Name == "artist")
{
writer.WriteElementString("artist", reader.ReadElementString());
}
}
}
writer.WriteEndDocument();
Console.WriteLine("XML file saved to {0}", outputFile);
}
}
}