本文整理汇总了C#中System.Xml.XmlTextWriter.WriteStartDocument方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlTextWriter.WriteStartDocument方法的具体用法?C# System.Xml.XmlTextWriter.WriteStartDocument怎么用?C# System.Xml.XmlTextWriter.WriteStartDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlTextWriter
的用法示例。
在下文中一共展示了System.Xml.XmlTextWriter.WriteStartDocument方法的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 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();
}
}
示例3: Create
/// <summary>
/// Construct an StreamContent from a provided populated OFX object
/// </summary>
/// <param name="ofxObject">A populated OFX message with request or response data</param>
/// <returns>Created StreamContent ready to send with HttpClient.Post</returns>
public static StreamContent Create(Protocol.OFX ofxObject)
{
// Serialized data will be written to a MemoryStream
var memoryStream = new System.IO.MemoryStream();
// XMLWriter will be used to encode the data using UTF8Encoding without a Byte Order Marker (BOM)
var xmlWriter = new System.Xml.XmlTextWriter(memoryStream, new System.Text.UTF8Encoding(false));
// Write xml processing instruction
xmlWriter.WriteStartDocument();
// Our OFX protocol uses a version 2.0.0 header with 2.1.1 protocol body
xmlWriter.WriteProcessingInstruction("OFX", "OFXHEADER=\"200\" VERSION=\"211\" SECURITY=\"NONE\" OLDFILEUID=\"NONE\" NEWFILEUID=\"NONE\"");
// Don't include namespaces in the root element
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
// Generate XML to the stream
m_serializer.Serialize(xmlWriter, ofxObject, ns);
// Flush writer to stream
xmlWriter.Flush();
// Position the stream back to the start for reading
memoryStream.Position = 0;
// Wrap in our HttpContent-derived class to provide headers and other HTTP encoding information
return new StreamContent(memoryStream);
}
示例4: 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();
}
}
示例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;
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();
}
}
示例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: 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();
}
示例8: 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");
}
示例9: 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();
}
}
示例10: 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();
}
示例11: 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 = "";
}
}
}
示例12: 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();
}
}
示例13: 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;
}
}
示例14: 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;
int report_uid;
string version;
if (int.TryParse(Request.QueryString["project"], out project_uid) == false)
project_uid = 1;
if (int.TryParse(Request.QueryString["report_uid"], out report_uid) == false)
{
return;
}
version = Request.QueryString["version"];
if (version != null)
{
version.Trim();
if (version.Length == 0)
version = null;
}
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteStartElement("Outputs");
DB.ReserveReparse(project_uid, report_uid, version);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
}
示例15: tbnOK_Click
private void tbnOK_Click(object sender, EventArgs e)
{
object select = combxDataBases.SelectedValue;
if (select == null)
{
return;
}
ChoosedDBName = combxDataBases.SelectedValue.ToString();
string oldDefault = ds.Tables["root"].Rows[0][0].ToString();
if (oldDefault != ChoosedDBName && chkSetDefault.Checked)
{
ds.Tables["root"].Rows[0][0] = ChoosedDBName;
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(dbXmlFile, Encoding.UTF8);
writer.Formatting = System.Xml.Formatting.Indented;
writer.WriteStartDocument();
ds.WriteXml(writer);
writer.Close();
}
this.DialogResult = DialogResult.OK;
}