本文整理汇总了C#中System.Xml.XmlWriterSettings类的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlWriterSettings类的具体用法?C# System.Xml.XmlWriterSettings怎么用?C# System.Xml.XmlWriterSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Xml.XmlWriterSettings类属于命名空间,在下文中一共展示了System.Xml.XmlWriterSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: cloneWS
public void cloneWS()
{
Makro newws;
using (MemoryStream stream = new MemoryStream())
{
System.Xml.XmlWriterSettings ws = new System.Xml.XmlWriterSettings();
ws.NewLineHandling = System.Xml.NewLineHandling.Entitize;
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(Makro));
using (System.Xml.XmlWriter wr = System.Xml.XmlWriter.Create(stream, ws))
{
x.Serialize(wr, CurrentMakro);
}
stream.Position = 0;
System.Xml.XmlReaderSettings rs = new System.Xml.XmlReaderSettings();
using (System.Xml.XmlReader rd = System.Xml.XmlReader.Create(stream, rs))
{
newws = (Makro)x.Deserialize(rd, "");
}
//newws = (Makro)x.Deserialize(stream);
}
newws.Name += "_Copy";
Makros.Add(newws);
listBoxMakros.SelectedItem = newws;
}
示例2: Write
public static void Write(string file, Map overview)
{
if (string.IsNullOrEmpty(file))
throw new Exception("File Not Empty");
System.Xml.Serialization.XmlSerializer writer =
new System.Xml.Serialization.XmlSerializer(typeof(Map));
System.Xml.XmlWriterSettings setting = new System.Xml.XmlWriterSettings();
setting.Encoding = Encoding.UTF8;
setting.CloseOutput = true;
setting.NewLineChars = "\r\n";
setting.Indent = true;
if (!File.Exists(file))
{
using (Stream s = File.Open(file, FileMode.OpenOrCreate))
{
System.Xml.XmlWriter tmp = System.Xml.XmlWriter.Create(s, setting);
writer.Serialize(tmp, overview);
}
}
else
{
using (Stream s = File.Open(file, FileMode.Truncate))
{
System.Xml.XmlWriter tmp = System.Xml.XmlWriter.Create(s, setting);
writer.Serialize(tmp, overview);
}
}
}
示例3: Export
public static void Export(TLArtifactsCollection artifactsCollection, string outputPath, string collectionId, string name, string version, string description)
{
if (artifactsCollection == null)
{
throw new TraceLabSDK.ComponentException("Received null artifacts collection.");
}
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Indent = true;
settings.CloseOutput = true;
settings.CheckCharacters = true;
//create file
using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(outputPath, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("artifacts_collection");
WriteCollectionInfo(writer, collectionId, name, version, description);
WriteArtifacts(artifactsCollection, writer);
writer.WriteEndElement(); //artifacts_collection
writer.WriteEndDocument();
writer.Close();
}
System.Diagnostics.Trace.WriteLine("File created , you can find the file " + outputPath);
}
示例4: Export
public static void Export(TLSimilarityMatrix answerSet, string sourceId, string targetId, string outputPath)
{
if (answerSet == null)
{
throw new TraceLabSDK.ComponentException("Received null answer similarity matrix");
}
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Indent = true;
settings.CloseOutput = true;
settings.CheckCharacters = true;
//create file
using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(outputPath, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("answer_set");
WriteAnswerSetInfo(writer, sourceId, targetId);
WriteLinks(answerSet, writer);
writer.WriteEndElement(); //answer_set
writer.WriteEndDocument();
writer.Close();
}
System.Diagnostics.Trace.WriteLine("File created , you can find the file " + outputPath);
}
示例5: Writer
/// <summary>
/// Handling of data to be written.
/// Startup = Check if initial directory(s) have been created, ifnot do.
/// Remove = Removes an entry physically.
/// Entry = Saves an entry to a xml file via System.Xml.XmlWriter.
/// </summary>
void Writer(string Command, string Addition)
{
if (Command == "Startup") { //Check for initial directory(s).
if (System.IO.Directory.Exists(stringDirectoryProgramDatabase) == false) {
System.IO.Directory.CreateDirectory(stringDirectoryProgramDatabase);
}
} else if (Command == "Remove") { //Removes the physical from the HD.
// msgbox then delete stringFileCurrent+"day".xml
try {
messageboxResult = MessageBox.Show("Sure you want to delete Entry '" + TextboxDetailsMonth.Text + "-" + TextboxDetailsDay.Text + "_" + TextboxDetailsTime.Text + "_" + TextboxDetailsAuthor.Text + "'?", "Delete entry", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
} catch (System.Exception e) {
MessageBox.Show("You have to load the entry to mark it for remove.");
}
if (messageboxResult == DialogResult.Yes) {
//Delete directory
try {
System.IO.File.Delete(stringFileCurrent + "\\" + TextboxDetailsMonth.Text + "-" + TextboxDetailsDay.Text + "_" + TextboxDetailsTime.Text + "_" + TextboxDetailsAuthor.Text + ".xml");
} catch (System.Exception e) {
}
}
} else if (Command == "Entry") {
stringFileCurrent = stringDirectoryProgramDatabase;
stringFileCurrent += ToolstripButtonListSolution.Text;
stringFileCurrent += "\\";
stringFileCurrent += ToolstripButtonListProgram.Text;
stringFileCurrent += "\\";
stringFileCurrent += ToolstripButtonListVersion.Text;
if (Addition == "Save") {
// Create new structure from stringFileCurrent
System.IO.Directory.CreateDirectory(stringFileCurrent);
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Indent = true;
//Start WriterXML With stringFileCurrent + "Day".XML
using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(stringFileCurrent + "\\" + TextboxDetailsMonth.Text + "-" + TextboxDetailsDay.Text + "_" + TextboxDetailsTime.Text + "_" + TextboxDetailsAuthor.Text + ".xml", settings)) {
// Begin writing.
writer.WriteStartDocument();
writer.WriteStartElement("Information");
//> Information
writer.WriteElementString("Year", TextboxDetailsYear.Text);
writer.WriteElementString("Month", TextboxDetailsMonth.Text);
writer.WriteElementString("Day", TextboxDetailsDay.Text);
writer.WriteElementString("Time", TextboxDetailsTime.Text);
writer.WriteElementString("Author", TextboxDetailsAuthor.Text);
writer.WriteElementString("ReferenceID", TextboxDetailsReference.Text);
writer.WriteElementString("Reply", TextboxDetailsReplied.Text);
writer.WriteElementString("BugID", TextboxDetailsBugLink.Text);
writer.WriteElementString("Category", TextboxDetailsCategory.Text);
writer.WriteElementString("Change", TextboxDetailsChange.Text);
writer.WriteElementString("Description", TextboxDetailsDescription.Text);
writer.WriteElementString("Comment", TextboxDetailsComment.Text);
// End document.
writer.WriteEndDocument();
}
ListviewListEntries.Items.Insert(0, ToolstripButtonListVersion.Text);
ListviewListEntries.Items[0].Selected = true;
Reader("Load", "Version");
}
}
}
示例6: Serialize
public static string Serialize(object oObject, bool Indent = false)
{
System.Xml.Serialization.XmlSerializer oXmlSerializer = null;
System.Text.StringBuilder oStringBuilder = null;
System.Xml.XmlWriter oXmlWriter = null;
string sXML = null;
System.Xml.XmlWriterSettings oXmlWriterSettings = null;
System.Xml.Serialization.XmlSerializerNamespaces oXmlSerializerNamespaces = null;
// -----------------------------------------------------------------------------------------------------------------------
// Lage XML
// -----------------------------------------------------------------------------------------------------------------------
oStringBuilder = new System.Text.StringBuilder();
oXmlSerializer = new System.Xml.Serialization.XmlSerializer(oObject.GetType());
oXmlWriterSettings = new System.Xml.XmlWriterSettings();
oXmlWriterSettings.OmitXmlDeclaration = true;
oXmlWriterSettings.Indent = Indent;
oXmlWriter = System.Xml.XmlWriter.Create(new System.IO.StringWriter(oStringBuilder), oXmlWriterSettings);
oXmlSerializerNamespaces = new System.Xml.Serialization.XmlSerializerNamespaces();
oXmlSerializerNamespaces.Add(string.Empty, string.Empty);
oXmlSerializer.Serialize(oXmlWriter, oObject, oXmlSerializerNamespaces);
oXmlWriter.Close();
sXML = oStringBuilder.ToString();
return sXML;
}
示例7: writeValues
private void writeValues(System.IO.StringWriter oStringWriter)
{
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
settings.ConformanceLevel = System.Xml.ConformanceLevel.Auto;
System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(oStringWriter,settings);
writer.WriteRaw("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
writer.WriteStartElement("report");
writer.WriteAttributeString("date", DateTime.Now.ToString("yyyyMMdd_HHmm"));
foreach (var row in Current.Context.Report.GetResultElements())
{
writer.WriteStartElement("result");
foreach (var col in row.GetColumnNames())
{
writer.WriteStartElement("column");
writer.WriteAttributeString("name", col);
writer.WriteString(row.GetColumnValue(col));
writer.WriteEndElement();
}
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.Flush();
}
示例8: Build
public object Build(
XmlUtilities.XmlModule moduleToBuild,
out bool success)
{
var node = moduleToBuild.OwningNode;
var xmlLocation = moduleToBuild.Locations[XmlUtilities.XmlModule.OutputFile];
var xmlPath = xmlLocation.GetSinglePath();
if (null == xmlPath)
{
throw new Bam.Core.Exception("XML output path was not set");
}
// dependency checking
{
var outputFiles = new Bam.Core.StringArray();
outputFiles.Add(xmlPath);
if (!RequiresBuilding(outputFiles, new Bam.Core.StringArray()))
{
Bam.Core.Log.DebugMessage("'{0}' is up-to-date", node.UniqueModuleName);
success = true;
return null;
}
}
Bam.Core.Log.Info("Writing XML file '{0}'", xmlPath);
// create all directories required
var dirsToCreate = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.Directory, Bam.Core.Location.EExists.WillExist);
foreach (var dir in dirsToCreate)
{
var dirPath = dir.GetSinglePath();
NativeBuilder.MakeDirectory(dirPath);
}
// serialize the XML to disk
var settings = new System.Xml.XmlWriterSettings();
settings.CheckCharacters = true;
settings.CloseOutput = true;
settings.ConformanceLevel = System.Xml.ConformanceLevel.Auto;
settings.Indent = true;
settings.IndentChars = new string(' ', 4);
settings.NewLineChars = "\n";
settings.NewLineHandling = System.Xml.NewLineHandling.None;
settings.NewLineOnAttributes = false;
settings.OmitXmlDeclaration = false;
settings.Encoding = new System.Text.UTF8Encoding(false); // do not write BOM
using (var xmlWriter = System.Xml.XmlWriter.Create(xmlPath, settings))
{
moduleToBuild.Document.WriteTo(xmlWriter);
xmlWriter.WriteWhitespace(settings.NewLineChars);
}
success = true;
return null;
}
示例9: GetSettingXml
public string GetSettingXml()
{
System.Xml.Serialization.XmlSerializer serializer =
new System.Xml.Serialization.XmlSerializer(typeof(AlarmSetting));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Xml.XmlWriterSettings xmlwritersetting = new System.Xml.XmlWriterSettings();
xmlwritersetting.Encoding = Encoding.UTF8;
System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create(ms, xmlwritersetting);
serializer.Serialize(xmlWriter, this);
return Encoding.GetEncoding("utf-8").GetString(ms.ToArray());
}
示例10: XmlDocWriterBase
public XmlDocWriterBase(string filename)
{
this.stack = new Stack<string>();
if (filename == null)
{
throw new System.ArgumentNullException("filename");
}
var settings = new System.Xml.XmlWriterSettings();
settings.Indent = true;
this._xw = System.Xml.XmlWriter.Create(filename, settings);
}
示例11: CreateReportXAML
/// <summary>
/// Creates the report.
/// </summary>
public string CreateReportXAML(string serverUrl, ReportConfig config)
{
if (config.StaticXAMLReport != null)
return config.StaticXAMLReport;
// load the xslt template
System.Xml.Xsl.XslCompiledTransform xslt = new System.Xml.Xsl.XslCompiledTransform();
try {
LoadTemplate(xslt, serverUrl, config.ReportGroup, config.ReportTemplate);
}
catch (System.Exception) {
throw new ScrumFactory.Exceptions.ScrumFactoryException("Error_reading_report_template");
}
// creates a buffer stream to write the report context in XML
System.IO.BufferedStream xmlBuffer = new System.IO.BufferedStream(new System.IO.MemoryStream());
System.Xml.XmlWriterSettings writerSettings = new System.Xml.XmlWriterSettings();
writerSettings.CheckCharacters = false;
writerSettings.OmitXmlDeclaration = true;
System.Xml.XmlWriter reportDataStream = System.Xml.XmlWriter.Create(xmlBuffer, writerSettings);
// write XML start tag
reportDataStream.WriteStartDocument();
reportDataStream.WriteStartElement("ReportData");
// create report context in XML
CreateDefaultXMLContext(reportDataStream, writerSettings, serverUrl, config);
// finish XML document
reportDataStream.WriteEndDocument();
reportDataStream.Flush();
xmlBuffer.Seek(0, System.IO.SeekOrigin.Begin);
// debug
//System.IO.StreamReader s = new System.IO.StreamReader(xmlBuffer);
//string ss = s.ReadToEnd();
System.Xml.XmlReaderSettings readerSettings = new System.Xml.XmlReaderSettings();
readerSettings.CheckCharacters = false;
System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(xmlBuffer, readerSettings);
// creates a buffer stream to write the XAML flow document
System.IO.StringWriter xamlBuffer = new System.IO.StringWriter();
System.Xml.XmlWriter xamlWriter = System.Xml.XmlWriter.Create(xamlBuffer, writerSettings);
// creates the flow document XMAL
xslt.Transform(xmlReader, xamlWriter);
// sets the flow document at the view
return xamlBuffer.ToString();
}
示例12: ToFile
public void ToFile(string fileName)
{
XmlSerializer xs = new XmlSerializer(typeof(gpx));
FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
System.Xml.XmlWriterSettings xmlWriterSettings = new System.Xml.XmlWriterSettings();
xmlWriterSettings.Indent = false;
xmlWriterSettings.NewLineOnAttributes = false;
System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create(fs, xmlWriterSettings);
xs.Serialize(xmlWriter, this);
fs.Close();
//xmlWriter.Close();
fs.Dispose();
}
示例13: PostExecution
PostExecution()
{
var graph = Bam.Core.Graph.Instance;
var solution = graph.MetaData as VSSolution;
if (0 == solution.Projects.Count())
{
throw new Bam.Core.Exception("No projects were generated");
}
var xmlWriterSettings = new System.Xml.XmlWriterSettings
{
OmitXmlDeclaration = false,
Encoding = new System.Text.UTF8Encoding(false), // no BOM (Byte Ordering Mark)
NewLineChars = System.Environment.NewLine,
Indent = true
};
foreach (var project in solution.Projects)
{
var projectPathDir = System.IO.Path.GetDirectoryName(project.ProjectPath);
if (!System.IO.Directory.Exists(projectPathDir))
{
System.IO.Directory.CreateDirectory(projectPathDir);
}
var projectXML = project.Serialize();
using (var xmlwriter = System.Xml.XmlWriter.Create(project.ProjectPath, xmlWriterSettings))
{
projectXML.WriteTo(xmlwriter);
}
Bam.Core.Log.DebugMessage(PrettyPrintXMLDoc(projectXML));
var projectFilterXML = project.Filter.Serialize();
using (var xmlwriter = System.Xml.XmlWriter.Create(project.ProjectPath + ".filters", xmlWriterSettings))
{
projectFilterXML.WriteTo(xmlwriter);
}
Bam.Core.Log.DebugMessage(PrettyPrintXMLDoc(projectFilterXML));
}
var solutionPath = Bam.Core.TokenizedString.Create("$(buildroot)/$(masterpackagename).sln", null).Parse();
var solutionContents = solution.Serialize();
using (var writer = new System.IO.StreamWriter(solutionPath))
{
writer.Write(solutionContents);
}
Bam.Core.Log.DebugMessage(solutionContents.ToString());
Bam.Core.Log.Info("Successfully created Visual Studio solution file for package '{0}'\n\t{1}", graph.MasterPackage.Name, solutionPath);
}
示例14: PrepareDependenciesDump
public void PrepareDependenciesDump ()
{
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
var depsFile = File.OpenWrite ("linker-dependencies.xml.gz");
zipStream = new GZipStream (depsFile, CompressionMode.Compress);
writer = System.Xml.XmlWriter.Create (zipStream, settings);
writer.WriteStartDocument ();
writer.WriteStartElement ("dependencies");
writer.WriteStartAttribute ("version");
writer.WriteString ("1.0");
writer.WriteEndAttribute ();
}
示例15: PrettyPrintXMLDoc
PrettyPrintXMLDoc(
System.Xml.XmlDocument document)
{
var content = new System.Text.StringBuilder();
var settings = new System.Xml.XmlWriterSettings
{
Indent = true,
NewLineChars = System.Environment.NewLine,
Encoding = new System.Text.UTF8Encoding(false) // no BOM
};
using (var writer = System.Xml.XmlWriter.Create(content, settings))
{
document.Save(writer);
}
return content.ToString();
}