本文整理汇总了C#中System.Xml.XmlWriter.WriteString方法的典型用法代码示例。如果您正苦于以下问题:C# XmlWriter.WriteString方法的具体用法?C# XmlWriter.WriteString怎么用?C# XmlWriter.WriteString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlWriter
的用法示例。
在下文中一共展示了XmlWriter.WriteString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ON2XML
/// <summary>
/// Creates XML elements from the data of the system.
/// </summary>
/// <param name="xmlWriter">Object with the XML message to add new information and return to client side</param>
/// <param name="val">Value to be puted inside the XML message</param>
/// <param name="dtdVersion">Version of the DTD that follows the XML message</param>
/// <param name="xmlElement">Element of the XML that is checked</param>
public static void ON2XML(XmlWriter xmlWriter, ONDateTime val, double dtdVersion, string xmlElement)
{
if (val == null)
{
if (xmlElement == ONXml.XMLTAG_V)
xmlWriter.WriteElementString(xmlElement, "");
else
xmlWriter.WriteElementString(ONXml.XMLTAG_NULL, null);
}
else
{
if (dtdVersion < 2.0) // Apply the locale format
xmlWriter.WriteElementString(xmlElement, val.TypedValue.ToString());
else
{
xmlWriter.WriteStartElement(xmlElement);
if (xmlElement == ONXml.XMLTAG_OIDFIELD && dtdVersion > 2.0)
xmlWriter.WriteAttributeString("Type", "datetime");
if (val.TypedValue.Millisecond == 0)
xmlWriter.WriteString(val.TypedValue.ToString("yyyy-MM-ddTHH:mm:ss"));
else
xmlWriter.WriteString(val.TypedValue.ToString("yyyy-MM-ddTHH:mm:ss.fff"));
xmlWriter.WriteEndElement();
}
}
}
示例2: ON2XML
/// <summary>
/// Creates XML elements from the data of the system.
/// </summary>
/// <param name="xmlWriter">Object with the XML message to add new information and return to client side</param>
/// <param name="val">Value to be puted inside the XML message</param>
/// <param name="dtdVersion">Version of the DTD that follows the XML message</param>
/// <param name="xmlElement">Element of the XML that is checked</param>
public static void ON2XML(XmlWriter xmlWriter, ONBool val, double dtdVersion, string xmlElement)
{
if (val == null)
{
if (xmlElement == ONXml.XMLTAG_V)
xmlWriter.WriteElementString(xmlElement, "");
else
xmlWriter.WriteElementString(ONXml.XMLTAG_NULL, null);
}
else
{
if (dtdVersion < 2.0) // Apply the locale format
{
if (val.TypedValue)
xmlWriter.WriteElementString(xmlElement, "Verdadero");
else
xmlWriter.WriteElementString(xmlElement, "Falso");
}
else
{
xmlWriter.WriteStartElement(xmlElement);
if (xmlElement == ONXml.XMLTAG_OIDFIELD && dtdVersion > 2.0)
xmlWriter.WriteAttributeString("Type", "bool");
if (val.TypedValue)
xmlWriter.WriteString("true");
else
xmlWriter.WriteString("false");
xmlWriter.WriteEndElement();
}
}
}
示例3: WriteXml
internal override void WriteXml(XmlWriter writer)
{
if (base.IsSlot)
{
writer.WriteStartElement("Property", NodeQuery.XmlNamespace);
writer.WriteAttributeString("name", base.PropertySlot.Name);
writer.WriteEndElement();
}
else if (!IsValue)
{
writer.WriteStartElement("Property", NodeQuery.XmlNamespace);
writer.WriteAttributeString("name", base.NodeAttribute.ToString());
writer.WriteEndElement();
}
else
{
if (_value == null)
writer.WriteElementString("NullValue", NodeQuery.XmlNamespace, null);
else if (_value is string)
writer.WriteString((string)_value);
else if (_value is int)
writer.WriteString(XmlConvert.ToString((int)_value));
else if (_value is decimal)
writer.WriteString(XmlConvert.ToString((decimal)_value));
if (_value is DateTime)
writer.WriteString(XmlConvert.ToString((DateTime)_value, XmlDateTimeSerializationMode.Unspecified));
}
}
示例4: WriteXmlInnerError
private static void WriteXmlInnerError(XmlWriter writer, ODataInnerError innerError, string innerErrorElementName, int recursionDepth, int maxInnerErrorDepth)
{
recursionDepth++;
if (recursionDepth > maxInnerErrorDepth)
{
throw new ODataException(Strings.ValidationUtils_RecursionDepthLimitReached(maxInnerErrorDepth));
}
writer.WriteStartElement("m", innerErrorElementName, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
string text = innerError.Message ?? string.Empty;
writer.WriteStartElement("message", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
writer.WriteString(text);
writer.WriteEndElement();
string str2 = innerError.TypeName ?? string.Empty;
writer.WriteStartElement("type", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
writer.WriteString(str2);
writer.WriteEndElement();
string str3 = innerError.StackTrace ?? string.Empty;
writer.WriteStartElement("stacktrace", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
writer.WriteString(str3);
writer.WriteEndElement();
if (innerError.InnerError != null)
{
WriteXmlInnerError(writer, innerError.InnerError, "internalexception", recursionDepth, maxInnerErrorDepth);
}
writer.WriteEndElement();
}
示例5: FormatXml
protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
{
writer.WriteStartElement("LogEntry");
writer.WriteStartElement("Level");
writer.WriteString(loggingEvent.Level.DisplayName);
writer.WriteEndElement();
writer.WriteStartElement("Message");
writer.WriteString(loggingEvent.RenderedMessage);
writer.WriteEndElement();
writer.WriteStartElement("Details");
if (loggingEvent.ExceptionObject != null)
writer.WriteString(loggingEvent.ExceptionObject.ToString());
writer.WriteEndElement();
writer.WriteStartElement("StackTrace");
if (loggingEvent.ExceptionObject != null)
writer.WriteString(string.IsNullOrEmpty(loggingEvent.ExceptionObject.StackTrace) ? string.Empty : loggingEvent.ExceptionObject.StackTrace);
writer.WriteEndElement();
writer.WriteStartElement("TimeStamp");
writer.WriteString(loggingEvent.TimeStamp.ToString("dd/MM/yyyy HH:mm:ss"));
writer.WriteEndElement();
writer.WriteEndElement();
}
示例6: WriteTo
internal override void WriteTo(XmlWriter writer)
{
base.WriteTo(writer);
writer.WriteStartElement("MessageNumber");
writer.WriteString(this.sequenceNumber.ToString(CultureInfo.InvariantCulture));
writer.WriteEndElement();
writer.WriteStartElement("LastMessage");
writer.WriteString(this.isLast.ToString(CultureInfo.InvariantCulture));
writer.WriteEndElement();
}
示例7: WriteXmlData
protected override void WriteXmlData(XmlWriter writer)
{
var data = (WhoAndWhenData)GetData();
writer.WriteStartElement("Who");
writer.WriteString(data.Who == null ? string.Empty : data.Who.Path);
writer.WriteEndElement();
writer.WriteStartElement("When");
writer.WriteString(XmlConvert.ToString(data.When, XmlDateTimeSerializationMode.Unspecified));
writer.WriteEndElement();
}
示例8: writeToXml
public override void writeToXml(XmlWriter xmlWriter)
{
xmlWriter.WriteStartElement(CENTER);
xmlWriter.WriteString(center.X + "," + center.Y + "," + center.Z);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement(QUATERNIONS);
xmlWriter.WriteString(quaternion.W + "," + quaternion.X + "," + quaternion.Y + "," + quaternion.Z);
xmlWriter.WriteEndElement();
}
示例9: ExportAsXml
public override bool ExportAsXml(XmlWriter writer)
{
writer.WriteStartElement("name");
writer.WriteString(Name);
writer.WriteEndElement();
writer.WriteStartElement("data");
writer.WriteString(Data);
writer.WriteEndElement();
return true;
}
示例10: WriteSpellXml
private void WriteSpellXml(XmlWriter w, string name, SpellDescription spell)
{
string shortName = Regex.Replace(name, "[^\\w]", "").ToLower();
w.WriteStartElement(shortName);
w.WriteStartElement("name");
w.WriteAttributeString("type", "string");
w.WriteString(name);
w.WriteEndElement(); // name
w.WriteStartElement("school");
w.WriteAttributeString("type", "string");
w.WriteString(spell.School);
w.WriteEndElement(); // school
w.WriteStartElement("level");
w.WriteAttributeString("type", "string");
w.WriteString(spell.Level);
w.WriteEndElement(); // level
w.WriteStartElement("components");
w.WriteAttributeString("type", "string");
w.WriteString(spell.Components);
w.WriteEndElement(); // components
w.WriteStartElement("castingtime");
w.WriteAttributeString("type", "string");
w.WriteString(spell.CastingTime);
w.WriteEndElement(); // castingtime
w.WriteStartElement("range");
w.WriteAttributeString("type", "string");
w.WriteString(spell.Range);
w.WriteEndElement(); // range
w.WriteStartElement("effect");
w.WriteAttributeString("type", "string");
w.WriteString(spell.Effect);
w.WriteEndElement(); // effect
w.WriteStartElement("duration");
w.WriteAttributeString("type", "string");
w.WriteString(spell.Duration);
w.WriteEndElement(); // duration
w.WriteStartElement("save");
w.WriteAttributeString("type", "string");
w.WriteString(spell.Save);
w.WriteEndElement(); // save
w.WriteStartElement("sr");
w.WriteAttributeString("type", "string");
w.WriteString(spell.AllowSpellResistance ? "Yes" : "No");
w.WriteEndElement(); // sr
w.WriteStartElement("description");
w.WriteAttributeString("type", "formattedtext");
var description = Regex.Replace(spell.LongDescription, @"[\r\n]+", "");
// replace HTML tags with their lowercase versions (formattedtext is case sensitive...)
// we don't support very many; h1, p, b, i, u, table, tr, td
description = Regex.Replace(description, @"<[^<>]+>", m => { return m.Value.ToLower(); });
w.WriteRaw(description);
w.WriteEndElement(); // description
w.WriteStartElement("shortdescription");
w.WriteAttributeString("type", "string");
w.WriteString(spell.ShortDescription);
w.WriteEndElement(); // shortdescription
w.WriteEndElement(); // <shortName>
}
示例11: WriteKeyValue
private static void WriteKeyValue(XmlWriter writer, string key, object value)
{
if (value.GetType() == typeof(string))
{
writer.WriteStartElement("String");
if (key != null)
writer.WriteAttributeString("Key", key);
writer.WriteString((string)value);
writer.WriteEndElement();
}
else if (value.GetType() == typeof(bool))
{
writer.WriteStartElement("Boolean");
if (key != null)
writer.WriteAttributeString("Key", key);
writer.WriteString(value.ToString());
writer.WriteEndElement();
}
else if (value.GetType() == typeof(DateTime))
{
writer.WriteStartElement("DateTime");
if (key != null)
writer.WriteAttributeString("Key", key);
writer.WriteString(((DateTime)value).ToString("G"));
writer.WriteEndElement();
}
else if (value.GetType() == typeof(TimeSpan))
{
writer.WriteStartElement("TimeSpan");
if (key != null)
writer.WriteAttributeString("Key", key);
writer.WriteString(((TimeSpan)value).ToString("G"));
writer.WriteEndElement();
}
else if (value.GetType() == typeof(int))
{
writer.WriteStartElement("Int32");
if (key != null)
writer.WriteAttributeString("Key", key);
writer.WriteString(((int)value).ToString());
writer.WriteEndElement();
}
else if (value.GetType() == typeof(List<object>))
{
WriteArray(writer, key, (List<object>)value);
}
else if (value.GetType() == typeof(Dictionary<string, object>))
{
WriteDict(writer, key, (Dictionary<string, object>)value);
}
}
示例12: WriteEscapedXmlString
/// <summary>
/// Write a string to an XmlWriter
/// </summary>
/// <param name="writer">the writer to write to</param>
/// <param name="text">the string to write</param>
/// <remarks>
/// The test is escaped either using XML escape entities
/// or using CDATA sections.
/// </remarks>
public static void WriteEscapedXmlString(XmlWriter writer, string text)
{
// Write either escaped text or CDATA sections
int weightCData = 12 * (1 + CountSubstrings(text, CDATA_END));
int weightStringEscapes = 3*(CountSubstrings(text, "<") + CountSubstrings(text, ">")) + 4*CountSubstrings(text, "&");
if (weightStringEscapes <= weightCData)
{
// Write string using string escapes
writer.WriteString(text);
}
else
{
// Write string using CDATA section
int end = text.IndexOf(CDATA_END);
if (end < 0)
{
writer.WriteCData(text);
}
else
{
int start = 0;
while (end > -1)
{
writer.WriteCData(text.Substring(start, end - start));
if (end == text.Length - 3)
{
start = text.Length;
writer.WriteString(CDATA_END);
break;
}
else
{
writer.WriteString(CDATA_UNESCAPABLE_TOKEN);
start = end + 2;
end = text.IndexOf(CDATA_END, start);
}
}
if (start < text.Length)
{
writer.WriteCData(text.Substring(start));
}
}
}
}
示例13: SaveXml
public void SaveXml(CompilationUnit cu)
{
try
{
this.cu = cu;
is_assembly = cu.SyntaxTree is SyntaxTree.program_module || Compiler.is_dll(cu.SyntaxTree);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
settings.Indent = true;
xtw = XmlTextWriter.Create(Path.ChangeExtension(cu.UnitName, ".xml"), settings);
unit_name = Path.GetFileNameWithoutExtension(cu.UnitName);
xtw.WriteStartDocument();
xtw.WriteStartElement("doc");
if (is_assembly)
{
xtw.WriteStartElement("assembly");
xtw.WriteStartElement("name");
xtw.WriteString(Path.GetFileNameWithoutExtension(cu.UnitName));
xtw.WriteEndElement();
xtw.WriteEndElement();
}
else
{
xtw.WriteStartElement("unit");
xtw.WriteStartAttribute("name");
//xtw.WriteString((cu.SemanticTree as common_unit_node).unit_name);
xtw.WriteString(Path.GetFileNameWithoutExtension(cu.UnitName));
xtw.WriteEndAttribute();
xtw.WriteString(cu.SemanticTree.documentation);
xtw.WriteEndElement();
}
SaveMembers();
xtw.WriteEndElement();
xtw.Flush();
}
catch (Exception e)
{
}
try
{
if (xtw != null)
xtw.Close();
}
catch
{
}
}
示例14: FormatXml
protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
{
writer.WriteStartElement("LogEntry");
writer.WriteStartElement("Level");
writer.WriteString(loggingEvent.Level.DisplayName);
writer.WriteEndElement();
writer.WriteStartElement("Message");
writer.WriteCData(loggingEvent.RenderedMessage);
writer.WriteEndElement();
writer.WriteStartElement("Details");
if (loggingEvent.ExceptionObject != null)
writer.WriteCData(loggingEvent.ExceptionObject.ToString());
writer.WriteEndElement();
writer.WriteStartElement("StackTrace");
if (loggingEvent.ExceptionObject != null)
{
writer.WriteCData(string.IsNullOrEmpty(loggingEvent.ExceptionObject.StackTrace) ? string.Empty : loggingEvent.ExceptionObject.StackTrace);
//Exception Details
{
// Get stack trace for the exception with source file information
var st = new StackTrace(loggingEvent.ExceptionObject, true);
// Get the top stack frame
var frame = st.GetFrame(0);
if (frame != null)
{
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
string error_dtls = string.Format("\nFile: {0} -> Line:{1}", frame.GetFileName(), frame.GetFileLineNumber());
writer.WriteCData(error_dtls);
}
}
writer.WriteEndElement();
}
writer.WriteStartElement("TimeStamp");
writer.WriteString(loggingEvent.TimeStamp.ToString("dd/MM/yyyy HH:mm:ss"));
writer.WriteEndElement();
writer.WriteEndElement();
}
示例15: WriteShapes
private static void WriteShapes(XmlWriter writer, GraphAbstract g)
{
writer.WriteStartElement("g");
for(int k=0; k<g.Shapes.Count; k++) //<rect x="1140" y="30" width="100" height="20" style="fill: url(#two_hues); stroke: black;"/>
{
writer.WriteStartElement("rect");
writer.WriteAttributeString("x", g.Shapes[k].X.ToString());
writer.WriteAttributeString("y", g.Shapes[k].Y.ToString());
writer.WriteAttributeString("width", g.Shapes[k].Width.ToString());
writer.WriteAttributeString("height", g.Shapes[k].Height.ToString());
writer.WriteAttributeString("rx", "2");//rounded rectangle
//writer.WriteAttributeString("style", "fill: url(#two_hues); stroke: black;");
writer.WriteAttributeString("fill", string.Concat("#", (g.Shapes[k].ShapeColor.ToArgb() & 0x00FFFFFF).ToString("X6")) );
writer.WriteEndElement();
//<text text-anchor="middle" x="{$x+50}" y="{$y+15}">
writer.WriteStartElement("text");
writer.WriteAttributeString("x", Convert.ToString(g.Shapes[k].X + 10));
writer.WriteAttributeString("y", Convert.ToString(g.Shapes[k].Y + 15));
writer.WriteAttributeString("text-anchor", "start");
writer.WriteAttributeString("font-size", "9");
writer.WriteString(g.Shapes[k].Text);
writer.WriteEndElement();
}
writer.WriteEndElement();
}