本文整理汇总了C#中System.Xml.XmlWriterSettings类的典型用法代码示例。如果您正苦于以下问题:C# XmlWriterSettings类的具体用法?C# XmlWriterSettings怎么用?C# XmlWriterSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlWriterSettings类属于System.Xml命名空间,在下文中一共展示了XmlWriterSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateRequestXml
private string GenerateRequestXml(RequestInput input)
{
var sw = new StringWriter();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = false;
settings.OmitXmlDeclaration = true;
using (XmlWriter writer = XmlWriter.Create(sw, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("GenerateRequest");
writer.WriteElementString("pxPayUserId", pxPayUserId);
writer.WriteElementString("pxPayKey", pxPayKey);
PropertyInfo[] properties = input.GetType().GetProperties();
foreach (PropertyInfo prop in properties)
{
if (prop.CanWrite)
{
string val = (string)prop.GetValue(input, null);
if (val != null || val != string.Empty)
{
writer.WriteElementString(prop.Name, val);
}
}
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
}
return sw.ToString();
}
示例2: SaveCustomers
public static void SaveCustomers(List<Customer> customers)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = (" ");
XmlWriter xmlOut = XmlWriter.Create(CustomerDB.path, settings);
xmlOut.WriteStartDocument();
xmlOut.WriteStartElement("Customers");
foreach (Customer customer in customers)
{
switch (customer.GetType().Name)
{
case "Customer":
Write((Customer)customer, xmlOut);
break;
case "RetailCustomer":
WriteRetail((RetailCustomer)customer, xmlOut);
break;
case "WholesaleCustomer":
WriteWholesale((WholesaleCustomer)customer, xmlOut);
break;
default:
break;
}
}
xmlOut.WriteEndElement();
xmlOut.Close();
}
示例3: UpdateHeartbeat
public void UpdateHeartbeat()
{
// Create or Update External XML For Last Update Check DateTime
if (!File.Exists(CheckUpdateFile))
{
DateTime DateTimeNow = DateTime.Now;
XmlWriterSettings wSettings = new XmlWriterSettings();
wSettings.Indent = true;
XmlWriter writer = XmlWriter.Create(CheckUpdateFile, wSettings);
writer.WriteStartDocument();
writer.WriteComment("This file is generated by WWIV5TelnetServer - DO NOT MODIFY.");
writer.WriteStartElement("WWIV5UpdateStamp");
writer.WriteStartElement("LastChecked");
writer.WriteElementString("DateTime", DateTimeNow.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
// Do Update Check
updateTimer = new System.Timers.Timer(1000 * 60 * 60); // Hourly - Release Code
//updateTimer = new System.Timers.Timer(1000 * 10); // 10 Seconds for Testing Only
updateTimer.Elapsed += new ElapsedEventHandler(DoUpdateCheck);
updateTimer.AutoReset = true;
updateTimer.Enabled = true;
if (Properties.Settings.Default.checkUpdates == "On Startup")
{
DoUpdateCheck(null, null);
}
}
示例4: StringBuilder
string DotNetNuke.Entities.Modules.IPortable.ExportModule(int ModuleID)
{
StringBuilder strXML = new StringBuilder();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
XmlWriter Writer = XmlWriter.Create(strXML, settings);
ArrayList alCategories = GetCategories(PortalId, true, -3);
if (alCategories.Count > 0)
{
Writer.WriteStartElement("Categories");
foreach (CategoryInfo categoryInfo in alCategories)
{
Writer.WriteStartElement("Category");
Writer.WriteElementString("CategoryID", categoryInfo.CategoryID.ToString());
Writer.WriteElementString("Name", categoryInfo.CategoryName);
Writer.WriteElementString("Description", categoryInfo.CategoryDescription);
Writer.WriteElementString("Message", categoryInfo.Message);
Writer.WriteElementString("Archived", categoryInfo.Archived.ToString());
Writer.WriteElementString("OrderID", categoryInfo.OrderID.ToString());
Writer.WriteElementString("ParentCategoryID", categoryInfo.ParentCategoryID.ToString());
Writer.WriteEndElement();
}
Writer.WriteEndElement();
Writer.Close();
}
else
{
return String.Empty;
}
return strXML.ToString();
}
示例5: Compile
public void Compile()
{
ParsedPath resxPath = Target.InputPaths.Where(f => f.Extension == ".resx").First();
ParsedPath stringsPath = Target.OutputPaths.Where(f => f.Extension == ".strings").First();
List<ResourceItem> resources = ReadResources(resxPath);
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Indent = true;
xmlSettings.IndentChars = "\t";
using (XmlWriter xmlWriter = XmlWriter.Create(stringsPath, xmlSettings))
{
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Strings");
foreach (ResourceItem resource in resources)
{
if (resource.DataType == typeof(string))
{
string value = resource.ValueString;
xmlWriter.WriteStartElement("String");
xmlWriter.WriteAttributeString("Name", resource.Name);
xmlWriter.WriteString(value);
xmlWriter.WriteEndElement();
}
}
xmlWriter.WriteEndElement();
}
}
示例6: WrappedSerializer
internal WrappedSerializer(Serialization.DataFormat dataFormat, string streamName, TextWriter output) : base(dataFormat, streamName)
{
this.firstCall = true;
this.textWriter = output;
Serialization.DataFormat dataFormat1 = this.format;
switch (dataFormat1)
{
case Serialization.DataFormat.Text:
{
return;
}
case Serialization.DataFormat.XML:
{
XmlWriterSettings xmlWriterSetting = new XmlWriterSettings();
xmlWriterSetting.CheckCharacters = false;
xmlWriterSetting.OmitXmlDeclaration = true;
this.xmlWriter = XmlWriter.Create(this.textWriter, xmlWriterSetting);
this.xmlSerializer = new Serializer(this.xmlWriter);
return;
}
default:
{
return;
}
}
}
示例7: Unformat
public override string Unformat(string value)
{
if (string.IsNullOrWhiteSpace(value)) return null;
try
{
var stringBuilder = new StringBuilder();
var element = XElement.Parse(value);
var settings = new XmlWriterSettings
{
OmitXmlDeclaration = true,
Indent = false,
NewLineOnAttributes = false
};
using (var xmlWriter = XmlWriter.Create(stringBuilder, settings))
{
element.Save(xmlWriter);
}
return stringBuilder.ToString();
}
catch (Exception ex)
{
Log.Error($"Error while unformatting expected XML field {value}. The raw value will be used instead.", ex, this);
return value;
}
}
示例8: FixNuSpec
private static void FixNuSpec(ProjectVersion version, string file)
{
XNamespace ns = "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd";
var readerSettings = new XmlReaderSettings
{
IgnoreComments = false,
IgnoreWhitespace = false
};
XDocument doc;
using (var reader = XmlReader.Create(file, readerSettings))
{
doc = XDocument.Load(reader);
}
var versionElement = doc.Descendants(ns + "version").Single();
versionElement.Value = version.FullText;
var dependency = doc.Descendants(ns + "dependency").Where(x => (string)x.Attribute("id") == "NodaTime").FirstOrDefault();
if (dependency != null)
{
dependency.SetAttributeValue("version", version.Dependency);
}
var writerSettings = new XmlWriterSettings
{
Encoding = new UTF8Encoding(false),
Indent = false,
NewLineHandling = NewLineHandling.None,
};
using (var writer = XmlWriter.Create(file, writerSettings))
{
doc.Save(writer);
}
}
示例9: FormatText
static string FormatText(string text)
{
XmlTextWriter writer = null;
XmlDocument doc = new XmlDocument();
XmlWriterSettings xwSettings = new XmlWriterSettings();
string formattedText = string.Empty;
try
{
doc.LoadXml(text);
writer = new XmlTextWriter(".data.xml", null);
writer.Formatting = Formatting.Indented;
doc.Save(writer);
writer.Close();
using (StreamReader sr = new StreamReader(".data.xml"))
{
formattedText = sr.ReadToEnd();
}
}
finally
{
File.Delete(".data.xml");
}
return formattedText;
}
示例10: Execute
/// <summary>
/// Executes the request message on the target system and returns a response message.
/// If there isn’t a response, this method should return null
/// </summary>
public Message Execute(Message message, TimeSpan timeout)
{
if (message.Headers.Action != "Submit")
throw new ApplicationException("Unexpected Message Action");
//Parse the request message to extract the string and get out the body to send to the socket
XmlDictionaryReader rdr = message.GetReaderAtBodyContents();
rdr.Read();
string input = rdr.ReadElementContentAsString();
//Interact with the socket
this.Connection.Client.SendData(input);
string output = this.Connection.Client.ReceiveData();
Debug.WriteLine(output);
//Produce the response message
StringBuilder outputString = new StringBuilder();
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
XmlWriter replywriter = XmlWriter.Create(outputString, settings);
replywriter.WriteStartElement("SendResponse", "http://acme.wcf.lob.paymentapplication/");
replywriter.WriteStartElement("SendResult");
replywriter.WriteString(Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(output)));
replywriter.WriteEndElement();
replywriter.WriteEndElement();
replywriter.Close();
XmlReader replyReader = XmlReader.Create(new StringReader(outputString.ToString()));
Message response = Message.CreateMessage(MessageVersion.Default, "Submit/Response", replyReader);
return response;
}
示例11: prepareRAWPayload
private static byte[] prepareRAWPayload(string location, string temperature, string weatherType)
{
MemoryStream stream = new MemoryStream();
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true, Encoding = Encoding.UTF8 };
XmlWriter writer = XmlTextWriter.Create(stream, settings);
writer.WriteStartDocument();
writer.WriteStartElement("WeatherUpdate");
writer.WriteStartElement("Location");
writer.WriteValue(location);
writer.WriteEndElement();
writer.WriteStartElement("Temperature");
writer.WriteValue(temperature);
writer.WriteEndElement();
writer.WriteStartElement("WeatherType");
writer.WriteValue(weatherType);
writer.WriteEndElement();
writer.WriteStartElement("LastUpdated");
writer.WriteValue(DateTime.Now.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
byte[] payload = stream.ToArray();
return payload;
}
示例12: write
private void write(string filePath)
{
try
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.CloseOutput = true;
settings.CheckCharacters = true;
settings.ConformanceLevel = ConformanceLevel.Document;
settings.Encoding = Encoding.UTF8;
settings.Indent = true;
settings.IndentChars = "\t";
settings.NewLineChars = "\r\n";
using (XmlWriter writer = XmlWriter.Create(filePath, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("Config");
writer.WriteStartElement("FrequencyRange");
writer.WriteAttributeString("min", _minFreq.ToString());
writer.WriteAttributeString("max", _maxFreq.ToString());
writer.WriteEndElement();
writer.WriteElementString("DeviceID", _deviceId);
writer.WriteEndElement();
writer.WriteEndDocument();
}
}
catch (Exception ex)
{
Logger.Instance.Log(LogType.Error, "設定ファイルの書き込みに失敗: " + ex.Message + "\r\n" + ex.StackTrace);
}
}
示例13: Serialize
/// <summary>
/// Serializes the specified <see cref="Element"/> to XML.
/// </summary>
/// <param name="root">
/// The <c>Element</c> to serialize, including all its children.
/// </param>
/// <remarks>
/// The generated XML will be indented and have a full XML
/// declaration header.
/// </remarks>
/// <exception cref="ArgumentNullException">root is null.</exception>
public void Serialize(Element root)
{
var settings = new XmlWriterSettings();
settings.Indent = true;
//settings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
this.Serialize(root, settings);
}
示例14: CreateDefinitions
public void CreateDefinitions(WizardConfiguration wizardConfiguration)
{
var projectCollection = new XElement(Ns + "ProjectCollection");
var doc = new XDocument(
new XElement(Ns + "VSTemplate",
new XAttribute("Version", "3.0.0"),
new XAttribute("Type", "ProjectGroup"),
new XElement(Ns + "TemplateData",
new XElement(Ns + "Name", wizardConfiguration.Name),
new XElement(Ns + "Description", wizardConfiguration.Description),
new XElement(Ns + "ProjectType", wizardConfiguration.ProjectType),
new XElement(Ns + "DefaultName", wizardConfiguration.DefaultName),
new XElement(Ns + "SortOrder", wizardConfiguration.SortOrder),
new XElement(Ns + "Icon", wizardConfiguration.IconName)),
new XElement(Ns + "TemplateContent", projectCollection),
MakeWizardExtension(
"LogoFX.Tools.Templates.Wizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
$"LogoFX.Tools.Templates.Wizard.SolutionWizard")
));
XmlWriterSettings settings = new XmlWriterSettings
{
OmitXmlDeclaration = true,
Indent = true
};
var definitionFile = GetDefinitionFileName();
using (XmlWriter xw = XmlWriter.Create(definitionFile, settings))
{
doc.Save(xw);
}
}
示例15: MergeFrom
// This might better be rewrite to "examine two settings and return the existing one or new one if required".
internal void MergeFrom (XmlWriterSettings other)
{
CloseOutput |= other.CloseOutput;
OmitXmlDeclaration |= other.OmitXmlDeclaration;
if (ConformanceLevel == ConformanceLevel.Auto)
ConformanceLevel = other.ConformanceLevel;
}