本文整理汇总了C#中System.Xml.XmlTextWriter类的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlTextWriter类的具体用法?C# System.Xml.XmlTextWriter怎么用?C# System.Xml.XmlTextWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Xml.XmlTextWriter类属于命名空间,在下文中一共展示了System.Xml.XmlTextWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: ModifyProjectFile
public static void ModifyProjectFile(string filename)
{
if (!filename.ToLower().EndsWith("proj"))
{
throw new System.ArgumentException("Internal Error: ModifyProjectFile called with a file that is not a project");
}
Console.WriteLine("Modifying Project : {0}", filename);
// Load the Project file
var doc = System.Xml.Linq.XDocument.Load(filename);
// Modify the Source Control Elements
RemoveSCCElementsAttributes(doc.Root);
// Remove the read-only flag
var original_attr = System.IO.File.GetAttributes(filename);
System.IO.File.SetAttributes(filename, System.IO.FileAttributes.Normal);
// Write out the XML
using (var writer = new System.Xml.XmlTextWriter(filename, Encoding.UTF8))
{
writer.Formatting = System.Xml.Formatting.Indented;
doc.Save(writer);
writer.Close();
}
// Restore the original file attributes
System.IO.File.SetAttributes(filename, original_attr);
}
示例3: 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();
}
}
示例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 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();
}
}
示例5: 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);
}
示例6: CFDIXmlTextWriter
public CFDIXmlTextWriter(Comprobante comprobante, string fileName, Encoding encoding) {
this.comprobante = comprobante;
this.fileName = fileName;
this.encoding = encoding;
this.writer = new System.Xml.XmlTextWriter(fileName, System.Text.Encoding.UTF8);
}
示例7: Main
static void Main(string[] args)
{
var items = typeof(string).Assembly.GetTypes().Take(100);
var items2 = items.Select(i => new { i.Name, i.IsClass, i.IsEnum, i.IsValueType });
var datatable = Isotope.Data.DataUtil.DataTableFromEnumerable(items2);
string out_filename = "out.xaml";
var encoding = System.Text.Encoding.UTF8;
var x = new System.Xml.XmlTextWriter(out_filename, encoding);
var repdef = new Isotope.Reporting.ReportDefinition();
repdef.ReportHeaderDefinition.ReportTitle.TextStyle.FontSize = 18.0;
repdef.ReportHeaderDefinition.ReportTitle.TextStyle.FontWeight = Isotope.Reporting.FontWeight.Bold;
repdef.ReportHeaderDefinition.HeaderText.TextStyle.FontSize = 8.0;
var colstyle1 = new Isotope.Reporting.TableColumnStyle();
colstyle1.DetailTextStyle.FontWeight = Isotope.Reporting.FontWeight.Bold;
colstyle1.HorzontalAlignment = Isotope.Reporting.HorzontalAlignment.Right;
colstyle1.Width = 150;
repdef.Table.ColumnStyles.Add(colstyle1);
repdef.Table.TableStyle.CellSpacing = 10;
repdef.WriteXML(x,datatable);
x.Close();
}
示例8: 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();
}
}
示例9: 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);
}
}
}
示例10: 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();
}
}
示例11: 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();
}
示例12: SimpleSVGWriter
public SimpleSVGWriter(System.Xml.XmlTextWriter xw)
{
if (xw == null)
{
throw new System.ArgumentNullException();
}
this.xw = xw;
}
示例13: 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");
}
示例14: 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();
}
示例15: 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();
}
}