本文整理汇总了C#中System.Xml.XmlNode.WriteContentTo方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNode.WriteContentTo方法的具体用法?C# XmlNode.WriteContentTo怎么用?C# XmlNode.WriteContentTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlNode
的用法示例。
在下文中一共展示了XmlNode.WriteContentTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateHtml5StringFromXml
/// <summary>
/// Create a string that could be the contents of an HTML5 file and which corresponds to the specified DOM
/// (presumed to contain appropriate content).
/// This method has no business in this class except that it is so parallel to CreateHtml5FromXml that I wanted to keep them together.
/// </summary>
/// <param name="dom"></param>
public static string CreateHtml5StringFromXml(XmlNode dom)
{
var output = new StringBuilder();
using (var writer = XmlWriter.Create(output, GetXmlWriterSettingsForHtml5()))
{
dom.WriteContentTo(writer);
writer.Close();
}
return CleanupHtml5(output.ToString());
}
示例2: PrintNodeToConsole
public static void PrintNodeToConsole(XmlNode node)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
XmlWriter writer = XmlWriter.Create(Console.Out, settings);
node.WriteContentTo(writer);
writer.Flush();
Console.WriteLine();
}
示例3: WriteNodeContentTo
public void WriteNodeContentTo (XmlNode node)
{
node.WriteContentTo (output);
}
示例4: WriteRawContent
public void WriteRawContent(XmlNode node)
{
node.WriteContentTo(_xmlWriter);
}
示例5: GetIndentInnerXml
public static string GetIndentInnerXml(XmlNode node)
{
MemoryStream m = new MemoryStream();
XmlTextWriter w = new XmlTextWriter(m, Encoding.UTF8);
w.Formatting = Formatting.Indented;
w.Indentation = 4;
node.WriteContentTo(w);
w.Flush();
m.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(m, Encoding.UTF8);
string strText = sr.ReadToEnd();
sr.Close();
w.Close();
return strText;
}
示例6: DeserializeObject
static object DeserializeObject(IFormatter serializer, XmlNode element)
{
using (var memoryStream = new MemoryStream())
using (var xmlDictionaryWriter = XmlDictionaryWriter.CreateTextWriter(memoryStream))
{
element.WriteContentTo(xmlDictionaryWriter);
xmlDictionaryWriter.Flush();
memoryStream.Position = 0;
var deserializedObject = serializer.Deserialize(memoryStream);
return deserializedObject;
}
}
示例7: FormatXml
public static string FormatXml(XmlNode node)
{
String Result = "";
MemoryStream mStream = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(mStream, Encoding.Unicode);
try
{
writer.Formatting = Formatting.Indented;
// Write the XML into a formatting XmlTextWriter
node.WriteContentTo(writer);
writer.Flush();
mStream.Flush();
// Have to rewind the MemoryStream in order to read
// its contents.
mStream.Position = 0;
// Read MemoryStream contents into a StreamReader.
StreamReader sReader = new StreamReader(mStream);
// Extract the text from the StreamReader.
String FormattedXML = sReader.ReadToEnd();
Result = FormattedXML;
}
catch (XmlException)
{
Result = node.InnerXml;
}
writer.Close();
return Result;
}
示例8: CreateHtm5FromXml
public static TempFile CreateHtm5FromXml(XmlNode dom)
{
var temp = TempFile.TrackExisting(GetHtmlTempPath());
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.CheckCharacters = true;
settings.OmitXmlDeclaration = true;//we're aiming at normal html5, here. Not xhtml.
//CAN'T DO THIS: settings.OutputMethod = XmlOutputMethod.Html;
using (var writer = XmlWriter.Create(temp.Path, settings))
{
dom.WriteContentTo(writer);
writer.Close();
}
//now insert the non-xml-ish <!doctype html>
File.WriteAllText(temp.Path, "<!DOCTYPE html>\r\n" + File.ReadAllText(temp.Path));
return temp;
}