/// <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()); }
public static string ToString(System.Xml.XmlNode node, int indentation = 0) { using (var sw = new System.IO.StringWriter()) { using (var xw = new System.Xml.XmlTextWriter(sw)) { xw.Formatting = System.Xml.Formatting.Indented; xw.Indentation = indentation; node.WriteContentTo(xw); } return(sw.ToString()); } }
public static string xmlNodeToString(System.Xml.XmlNode node, int indentation) { using (var sw = new System.IO.StringWriter()) { using (var xw = new System.Xml.XmlTextWriter(sw)) { xw.Formatting = System.Xml.Formatting.Indented; xw.Indentation = indentation; if (node.ParentNode != null) { node.ParentNode.WriteContentTo(xw); } else { node.WriteContentTo(xw); } } return(sw.ToString()); } }
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(); }
public void WriteNodeContentTo (XmlNode node) { node.WriteContentTo (output); }
public void WriteRawContent(XmlNode node) { node.WriteContentTo(_xmlWriter); }
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; }
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; } }
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; }
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; }