本文整理汇总了C#中XmlTextWriter类的典型用法代码示例。如果您正苦于以下问题:C# XmlTextWriter类的具体用法?C# XmlTextWriter怎么用?C# XmlTextWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlTextWriter类属于命名空间,在下文中一共展示了XmlTextWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
}
示例2: 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();
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string folderpath = @"/var/www/weavver.com/messages";
if (!Directory.Exists(folderpath))
return;
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8);
writer.Indentation = 5;
writer.Formatting = Formatting.Indented;
WriteRSSPrologue(writer);
int i = 0;
Random r = new Random(10);
foreach (string file in System.IO.Directory.GetFiles(folderpath))
{
if (file.EndsWith("wav"))
{
string num = r.Next(10).ToString() + r.Next(10).ToString() + r.Next(10).ToString() + "-" + r.Next(10).ToString() + r.Next(10).ToString() + r.Next(10).ToString() + r.Next(10).ToString();
AddRSSItem(writer, "Jane Doe left you a message from 714-" + num, file, System.IO.Path.GetFileName(file), DateTime.Now.Subtract(TimeSpan.FromDays(i)).ToString("r"));
i++;
}
if (i > 10)
{
break;
}
}
WriteRSSClosing(writer);
writer.Flush();
writer.Close();
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.End();
}
示例4: Images
private void Images()
{
// Dataset containing
string catname ="Electricals";
ProductImageService.serProdctImage prodimage = new ProductImageService.serProdctImage();
DataSet dataset = prodimage.ProductImage_GetFashImgtwoForHandler(catname);
//string x = dataset.GetXml();
string xmlfile = dataset.GetXml();
XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath("~/xslt/HomeXSLTFile.xslt"));
XPathDocument xpathdocument = new
XPathDocument(xmlfile);
XmlTextWriter writer = new XmlTextWriter(Console.Out);
writer.Formatting = Formatting.Indented;
xslt.Transform(xpathdocument, null, writer, null);
//strstudentDetails = GetHtml(Server.MapPath("~/xsl/studentDetails.xsl"), strXML);
//XPathDocument myXPathDoc = new XPathDocument(myXmlFile);
//XslCompiledTransform myXslTrans = new XslCompiledTransform();
//myXslTrans.Load(myStyleSheet);
//XmlTextWriter myWriter = new XmlTextWriter("result.html", null);
//myXslTrans.Transform(myXPathDoc, null, myWriter);
}
示例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: WriteOutput
public static void WriteOutput(object data, Stream output, bool closeStreams )
{
if (data == output) return;
XmlDocument xml = data as XmlDocument;
if (xml != null)
{
XmlTextWriter xmlWriter = new XmlTextWriter(output, System.Text.Encoding.UTF8);
xml.WriteTo(xmlWriter);
xmlWriter.Flush();
}
Stream stream = data as Stream;
if (stream != null)
{
stream.Seek(0, SeekOrigin.Begin);
byte[] buffer = new byte[0x5000];
int read;
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
output.Write(buffer, 0, read);
if ( closeStreams ) stream.Close();
}
byte[] block = data as byte[];
if ( block != null && block.Length > 0 )
output.Write( block, 0, block.Length );
}
示例7: 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);
}
}
}
}
}
}
示例8: Xml
public static string Xml(this XElement e)
{
StringBuilder builder = new StringBuilder();
XmlTextWriter writer = new XmlTextWriter(new StringWriter(builder));
e.WriteTo(writer);
return builder.ToString();
}
示例9: DeserializeObject
// Here we deserialize it back into its original form
object DeserializeObject(string pXmlizedString)
{
XmlSerializer xs = new XmlSerializer(typeof(UserData));
MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
return xs.Deserialize(memoryStream);
}
示例10: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
Organization org = Organization.FromIdentity(Int32.Parse(Request.QueryString["OrganizationId"]));
ExternalActivities activities = ExternalActivities.ForOrganization(org);
activities.Sort(ExternalActivities.SortOrder.DateDescending);
Response.ContentType = "text/xml";
XmlWriter xml = new XmlTextWriter(Response.Output);
RssWriter rss = new RssWriter(xml);
rss.WriteHeader("Aktivism - " + org.Name, "http://www.piratpartiet.se", "Aktivism för Piratpartiet", null);
foreach (ExternalActivity activism in activities)
{
string title = "Aktivism i " + activism.Geography.Name;
if (title.Length > 60)
{
title = title.Substring(0, 57) + "...";
}
rss.WriteItem(title, "<img src=\"http://data.piratpartiet.se/Handlers/DisplayActivism.aspx?Id=" + activism.Identity.ToString() + "\" />", new Uri("http://data.piratpartiet.se/Handlers/DisplayActivism.aspx?Id=" + activism.Identity), activism.CreatedDateTime);
}
rss.Close();
xml.Close();
}
示例11: Main
public static int Main(string[] args)
{
if (args.Length < 1) {
Console.Error.WriteLine("Usage: RunMorphoCli tagger_file");
return 1;
}
Console.Error.Write("Loading tagger: ");
Tagger tagger = Tagger.load(args[0]);
if (tagger == null) {
Console.Error.WriteLine("Cannot load tagger from file '{0}'", args[0]);
return 1;
}
Console.Error.WriteLine("done");
Forms forms = new Forms();
TaggedLemmas lemmas = new TaggedLemmas();
TokenRanges tokens = new TokenRanges();
Tokenizer tokenizer = tagger.newTokenizer();
if (tokenizer == null) {
Console.Error.WriteLine("No tokenizer is defined for the supplied model!");
return 1;
}
XmlTextWriter xmlOut = new XmlTextWriter(Console.Out);
for (bool not_eof = true; not_eof; ) {
string line;
StringBuilder textBuilder = new StringBuilder();
// Read block
while ((not_eof = (line = Console.In.ReadLine()) != null) && line.Length > 0) {
textBuilder.Append(line).Append('\n');
}
if (not_eof) textBuilder.Append('\n');
// Tokenize and tag
string text = textBuilder.ToString();
tokenizer.setText(text);
int t = 0;
while (tokenizer.nextSentence(forms, tokens)) {
tagger.tag(forms, lemmas);
for (int i = 0; i < lemmas.Count; i++) {
TaggedLemma lemma = lemmas[i];
int token_start = (int)tokens[i].start, token_length = (int)tokens[i].length;
xmlOut.WriteString(text.Substring(t, token_start - t));
if (i == 0) xmlOut.WriteStartElement("sentence");
xmlOut.WriteStartElement("token");
xmlOut.WriteAttributeString("lemma", lemma.lemma);
xmlOut.WriteAttributeString("tag", lemma.tag);
xmlOut.WriteString(text.Substring(token_start, token_length));
xmlOut.WriteEndElement();
if (i + 1 == lemmas.Count) xmlOut.WriteEndElement();
t = token_start + token_length;
}
}
xmlOut.WriteString(text.Substring(t));
}
return 0;
}
示例12: WriteGestureLog
public void WriteGestureLog(Dictionary<String, Point3D> gestureDict, string timeStamp)
{
using (StringWriter sw = new StringWriter(_sBuilder))
{
using (XmlWriter xmlWriter = new XmlTextWriter(sw))
{
//START MOVEMENT
xmlWriter.WriteStartElement("mov");
xmlWriter.WriteStartAttribute("time_stamp");
xmlWriter.WriteValue(timeStamp);
xmlWriter.WriteEndAttribute();
//PRINT ALL JOINTS
foreach (var point in gestureDict)
{
xmlWriter.WriteStartElement(point.Key);//START JOINT
xmlWriter.WriteStartElement("x");
xmlWriter.WriteValue(point.Value.X);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("Y");
xmlWriter.WriteValue(point.Value.Y);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("Z");
xmlWriter.WriteValue(point.Value.Z);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();//END JOINT
}
xmlWriter.WriteEndElement();//END MOV
}
}
WriteToXMLLogFile();
}
示例13: 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();
}
示例14: ProcessSearchQueries
private static void ProcessSearchQueries(XmlTextWriter writer)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("../../complex-query.xml");
foreach (XmlNode query in xmlDoc.SelectNodes("/queries/query"))
{
string username = query.GetChildText("username");
int maxResults = 10;
var maxResultsAttrib = query.Attributes["max-results"];
if (maxResultsAttrib != null)
{
maxResults = int.Parse(maxResultsAttrib.Value);
}
List<string> tags = new List<string>();
foreach (XmlNode tag in query.SelectNodes("tag"))
{
tags.Add(tag.InnerText.Trim());
}
var bookmarks =
BookmarksDAL.FindBookmarks(username, tags, maxResults);
WriteBookmarks(writer, bookmarks);
}
}
示例15: ComplexSearch
static void ComplexSearch(XmlTextWriter writer)
{
BookstoreEntities context = new BookstoreEntities();
using (context)
{
XmlDocument doc = new XmlDocument();
doc.Load(Bookstore.Data.Settings.Default.complexSearchReadFile);
XmlNodeList queries = doc.SelectNodes("/review-queries/query");
foreach (XmlNode query in queries)
{
string type = query.Attributes["type"].Value;
if (type == "by-period")
{
string start = query.SelectSingleNode("start-date").InnerText;
string end = query.SelectSingleNode("end-date").InnerText;
IList<Review> found =
BookstoreDAL.FindReviewPeriod(start, end, context);
WriteResultSet(writer, found);
}
else if (type == "by-author")
{
string author = query.SelectSingleNode("author-name").InnerText;
IList<Review> found =
BookstoreDAL.FindReviewAuthor(author, context);
WriteResultSet(writer, found);
}
SearchLogsImporter.AddLog(DateTime.Now, query.OuterXml);
}
}
}