本文整理汇总了C#中System.Xml.XmlTextWriter.WriteStartElement方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlTextWriter.WriteStartElement方法的具体用法?C# System.Xml.XmlTextWriter.WriteStartElement怎么用?C# System.Xml.XmlTextWriter.WriteStartElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlTextWriter
的用法示例。
在下文中一共展示了System.Xml.XmlTextWriter.WriteStartElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteStartElement("Project");
writer.WriteStartElement("Items");
Dictionary<int, sProject> projectList;
DB.LoadProject(out projectList);
foreach (KeyValuePair<int, sProject> item in projectList)
{
writer.WriteStartElement("Item");
writer.WriteAttributeString("uid", item.Key.ToString());
writer.WriteAttributeString("name", item.Value.name);
writer.WriteEndElement();
}
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
}
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
int callstack_uid;
if (int.TryParse(Request.QueryString["callstack_uid"], out callstack_uid) == false)
callstack_uid = 1;
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteStartElement("Callstack");
DB.LoadCallstack(callstack_uid,
delegate(int depth, string funcname, string fileline)
{
writer.WriteStartElement("Singlestep");
writer.WriteAttributeString("depth", depth.ToString());
this.WriteCData(writer, "Funcname", funcname);
this.WriteCData(writer, "Fileline", fileline);
writer.WriteEndElement();
}
);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
}
示例3: IsolatedStorage_Read_and_Write_Sample
public static void IsolatedStorage_Read_and_Write_Sample()
{
string fileName = @"SelfWindow.xml";
IsolatedStorageFile storFile = IsolatedStorageFile.GetUserStoreForDomain();
IsolatedStorageFileStream storStream = new IsolatedStorageFileStream(fileName, FileMode.Create, FileAccess.Write);
System.Xml.XmlWriter writer = new System.Xml.XmlTextWriter(storStream, Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("Settings");
writer.WriteStartElement("UserID");
writer.WriteValue(42);
writer.WriteEndElement();
writer.WriteStartElement("UserName");
writer.WriteValue("kingwl");
writer.WriteEndElement();
writer.WriteEndElement();
writer.Flush();
writer.Close();
storStream.Close();
string[] userFiles = storFile.GetFileNames();
foreach(var userFile in userFiles)
{
if(userFile == fileName)
{
var storFileStreamnew = new IsolatedStorageFileStream(fileName,FileMode.Open,FileAccess.Read);
StreamReader storReader = new StreamReader(storFileStreamnew);
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(storReader);
int UserID = 0;
string UserName = null;
while(reader.Read())
{
switch(reader.Name)
{
case "UserID":
UserID = int.Parse(reader.ReadString());
break;
case "UserName":
UserName = reader.ReadString();
break;
default:
break;
}
}
Console.WriteLine("{0} {1}", UserID, UserName);
storFileStreamnew.Close();
}
}
storFile.Close();
}
示例4: SaveToFile
protected virtual void SaveToFile(DataSet pDataSet)
{
if (m_FileName == null)
throw new ApplicationException("FileName is null");
byte[] completeByteArray;
using (System.IO.MemoryStream fileMemStream = new System.IO.MemoryStream())
{
System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(fileMemStream, System.Text.Encoding.UTF8);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("filedataset", c_DataNamespace);
xmlWriter.WriteStartElement("header", c_DataNamespace);
//File Version
xmlWriter.WriteAttributeString(c_FileVersion, c_FileVersionNumber.ToString());
//Data Version
xmlWriter.WriteAttributeString(c_DataVersion, GetDataVersion().ToString());
//Data Format
xmlWriter.WriteAttributeString(c_DataFormat, ((int)mSaveDataFormat).ToString());
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("data", c_DataNamespace);
byte[] xmlByteArray;
using (System.IO.MemoryStream xmlMemStream = new System.IO.MemoryStream())
{
StreamDataSet.Write(xmlMemStream, pDataSet, mSaveDataFormat);
//pDataSet.WriteXml(xmlMemStream);
xmlByteArray = xmlMemStream.ToArray();
xmlMemStream.Close();
}
xmlWriter.WriteBase64(xmlByteArray, 0, xmlByteArray.Length);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Flush();
completeByteArray = fileMemStream.ToArray();
fileMemStream.Close();
}
//se tutto è andato a buon fine scrivo effettivamente il file
using (System.IO.FileStream fileStream = new System.IO.FileStream(m_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
fileStream.Write(completeByteArray, 0, completeByteArray.Length);
fileStream.Close();
}
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
int project_uid;
if (int.TryParse(Request.QueryString["project"], out project_uid) == false)
project_uid = 1;
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteStartElement("Report");
writer.WriteAttributeString("project", project_uid.ToString());
writer.WriteStartElement("Items");
DB.LoadReportDeleted(project_uid,
delegate(int report_uid, string login_id, string ipaddr, DateTime reported_time, string relative_time, int callstack_uid, string funcname, string version, string filename, string assigned, string uservoice, int num_comments)
{
writer.WriteStartElement("Item");
writer.WriteAttributeString("report_uid", report_uid.ToString());
writer.WriteAttributeString("login_id", login_id);
writer.WriteAttributeString("ipaddr", ipaddr);
writer.WriteAttributeString("reported_time", reported_time.ToString());
writer.WriteAttributeString("relative_time", relative_time);
writer.WriteAttributeString("callstack_uid", callstack_uid.ToString());
writer.WriteAttributeString("assigned", assigned);
writer.WriteAttributeString("num_comments", num_comments.ToString());
this.WriteCData(writer, "Funcname", funcname);
this.WriteCData(writer, "Version", version);
this.WriteCData(writer, "Filename", filename);
this.WriteCData(writer, "Uservoice", uservoice);
writer.WriteEndElement();
}
);
writer.WriteEndElement(); // Items
writer.WriteEndElement(); // Report
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
}
示例6: CriarArquivoXML
/// <summary>
/// Método para criação do Arquivo XML com Configurações do usuário.
/// </summary>
public static void CriarArquivoXML()
{
try
{
System.Xml.XmlTextWriter xtrPrefs = new System.Xml.XmlTextWriter(Directories.UserPrefsDirectory +
@"\UserPrefs.config", System.Text.Encoding.UTF8);
// Inicia o documento XML.
xtrPrefs.WriteStartDocument();
// Escreve elemento raiz.
xtrPrefs.WriteStartElement("Directories");
// Escreve sub-Elementos.
xtrPrefs.WriteElementString("Starbound", Directories.StarboundDirectory);
xtrPrefs.WriteElementString("Mods", Directories.ModsDirectory);
// Encerra o elemento raiz.
xtrPrefs.WriteEndElement();
// Escreve o XML para o arquivo e fecha o objeto escritor.
xtrPrefs.Close();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
示例7: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
int report_uid;
int new_state;
if (int.TryParse(Request.QueryString["report_uid"], out report_uid) == false)
{
return;
}
if (int.TryParse(Request.QueryString["state"], out new_state) == false)
new_state = 1;
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteStartElement("Outputs");
DB.UpdateReportState(report_uid, new_state);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
}
示例8: GenerateNotificationContent
/// <summary>
/// Generates the content of the notification.
/// </summary>
/// <param name="template">The template.</param>
/// <param name="data">The data.</param>
/// <returns></returns>
public static string GenerateNotificationContent(string template, Dictionary<string, object> data)
{
using(var writer = new System.IO.StringWriter())
{
using (System.Xml.XmlWriter xml = new System.Xml.XmlTextWriter(writer))
{
xml.WriteStartElement("root");
foreach (DictionaryEntry de in HostSettingManager.GetHostSettings())
xml.WriteElementString(string.Concat("HostSetting_", de.Key), de.Value.ToString());
foreach (var item in data.Keys)
{
if (item.StartsWith("RawXml"))
{
xml.WriteRaw(data[item].ToString());
}
else if (item.GetType().IsClass)
{
xml.WriteRaw(data[item].ToXml());
}
else
{
xml.WriteElementString(item, data[item].ToString());
}
}
xml.WriteEndElement();
return XmlXslTransform.Transform(writer.ToString(), template);
}
}
}
示例9: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
int project_uid;
short fromDate = 0;
short toDate = 0;
if (int.TryParse(Request.QueryString["project"], out project_uid) == false)
project_uid = 1;
if (short.TryParse(Request.QueryString["from"], out fromDate) == false)
fromDate = 0;
if (short.TryParse(Request.QueryString["to"], out toDate) == false)
toDate = 0;
if (toDate > fromDate)
return;
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteStartElement("Counts");
Dictionary<string, int> dailyCountList = new Dictionary<string, int>();
for (int i = toDate; i < fromDate; i++)
{
TimeSpan oneDay = new TimeSpan(i, 0, 0, 0);
DateTime saveDate = DateTime.Now.Subtract(oneDay);
string date = string.Format("{0:0000}-{1:00}-{2:00}", saveDate.Year, saveDate.Month, saveDate.Day);
dailyCountList[date] = 0;
}
DB.LoadDailyCount(project_uid, fromDate, toDate,
delegate(string date, int count)
{
dailyCountList[date] = count;
}
);
foreach (KeyValuePair<string,int> v in dailyCountList)
{
writer.WriteStartElement("Count");
writer.WriteAttributeString("date", v.Key);
writer.WriteAttributeString("count", v.Value.ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
}
示例10: Initialize
public override void Initialize()
{
base.Initialize ();
System.IO.StreamWriter oStream = new System.IO.StreamWriter(_FilePath, false, System.Text.Encoding.UTF8);
_StreamWriter = new System.Xml.XmlTextWriter(oStream);
_StreamWriter.Formatting = System.Xml.Formatting.Indented;
_StreamWriter.WriteStartDocument();
_StreamWriter.WriteStartElement("ListItems");
}
示例11: SaveQuotes
/// <summary>
/// Saves movie quotes to an xml file
/// </summary>
/// <param name="movie">IIMDbMovie object</param>
/// <param name="xmlPath">path to save xml file to</param>
/// <param name="overwrite">set to true to overwrite existing xml file</param>
public static void SaveQuotes(
IIMDbMovie movie,
string xmlPath,
bool overwrite)
{
System.Xml.XmlTextWriter xmlWr;
try
{
if (File.Exists(xmlPath) == false
|| overwrite)
if (movie.Quotes.Count > 0)
{
xmlWr = new System.Xml.XmlTextWriter(xmlPath, Encoding.Default)
{Formatting = System.Xml.Formatting.Indented};
xmlWr.WriteStartDocument();
xmlWr.WriteStartElement("Quotes");
foreach (IList<IIMDbQuote> quoteBlock in movie.Quotes)
{
xmlWr.WriteStartElement("QuoteBlock");
foreach (IIMDbQuote quote in quoteBlock)
{
xmlWr.WriteStartElement("Quote");
xmlWr.WriteElementString("Character", quote.Character);
xmlWr.WriteElementString("QuoteText", quote.Text);
xmlWr.WriteEndElement();
}
xmlWr.WriteEndElement();
}
xmlWr.WriteEndElement();
xmlWr.WriteEndDocument();
xmlWr.Flush();
xmlWr.Close();
}
}
catch (Exception ex)
{
throw ex;
}
}
示例12: WriteConfig
// Lecture de la configuration
public static void WriteConfig()
{
string config_file = "config.xml";
var newconf = new System.Xml.XmlTextWriter(config_file, null);
newconf.WriteStartDocument();
newconf.WriteStartElement("config");
newconf.WriteElementString("last_update", LastUpdate.ToShortDateString());
newconf.WriteElementString("auth_token", AuthToken);
newconf.WriteEndElement();
newconf.WriteEndDocument();
newconf.Close();
}
示例13: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
int callstack_uid;
if (int.TryParse(Request.QueryString["callstack_uid"], out callstack_uid) == false)
callstack_uid = 1;
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteStartElement("Comment");
writer.WriteAttributeString("callstack_uid", callstack_uid.ToString());
DB.ForEachCallstackComment CommentWriter = delegate(string author, string comment, DateTime created)
{
writer.WriteStartElement("Item");
writer.WriteAttributeString("author", author);
writer.WriteAttributeString("created", created.ToString());
writer.WriteCData(comment);
writer.WriteEndElement();
};
DB.LoadCallstackComment(callstack_uid, CommentWriter);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
}
示例14: ReadConfig
// Lecture de la configuration
static void ReadConfig()
{
string config_file = "config.xml";
if (!System.IO.File.Exists(config_file))
{
var newconf = new System.Xml.XmlTextWriter(config_file, null);
newconf.WriteStartDocument();
newconf.WriteStartElement("config");
newconf.WriteElementString("last_update", "0");
newconf.WriteElementString("auth_token", "");
newconf.WriteEndElement();
newconf.WriteEndDocument();
newconf.Close();
}
var conf = new System.Xml.XmlTextReader(config_file);
string CurrentElement = "";
while (conf.Read())
{
switch(conf.NodeType) {
case System.Xml.XmlNodeType.Element:
CurrentElement = conf.Name;
break;
case System.Xml.XmlNodeType.Text:
if (CurrentElement == "last_update")
LastUpdate = DateTime.Parse(conf.Value);
if (CurrentElement == "auth_token")
AuthToken = conf.Value;
break;
}
}
conf.Close();
// On vérifie que le token est encore valide
if (AuthToken.Length > 0)
{
var flickr = new Flickr(Program.ApiKey, Program.SharedSecret);
try
{
Auth auth = flickr.AuthCheckToken(AuthToken);
Username = auth.User.UserName;
}
catch (FlickrApiException ex)
{
//MessageBox.Show(ex.Message, "Authentification requise",
// MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
AuthToken = "";
}
}
}
示例15: saveButton_Click
private void saveButton_Click(object sender, EventArgs e)
{
string settingsFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DichMusicHelperPathSettings.xml";
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(settingsFile, System.Text.Encoding.Unicode))
{
writer.WriteStartElement("PathSettings");
writer.WriteAttributeString("Path", pathTextBox.Text);
writer.WriteAttributeString("CreateFolder", createFolderBox.Checked.ToString());
writer.WriteEndElement();
writer.Close();
}
this.Close();
}