private void Write(XmlWriter outputWriter) { outputWriter.WriteStartDocument(); XStreamingElement root = MakeDzcTree(); root.WriteTo(outputWriter); }
private void Write(XmlWriter outputWriter) { outputWriter.WriteStartDocument(); //Write the XML declaration XStreamingElement root = MakeCxmlTree(); root.WriteTo(outputWriter); }
private static string CreateJsonString(XStreamingElement element) { using (var ms = new MemoryStream()) using (var writer = JsonReaderWriterFactory.CreateJsonWriter(ms, Encoding.Unicode)) { element.WriteTo(writer); writer.Flush(); return(Encoding.Unicode.GetString(ms.ToArray())); } }
public void AddAttributeAfterContent() { XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134"); XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134"); streamElement.Add(contact.Attribute("type")); using (XmlWriter w = XmlWriter.Create(new MemoryStream(), null)) { Assert.Throws <InvalidOperationException>(() => streamElement.WriteTo(w)); } }
private string CreateJsonString(XStreamingElement element) { MemoryStream memoryStream = new MemoryStream(); using (var writer = JsonReaderWriterFactory.CreateJsonWriter(memoryStream, Encoding.UTF8, true)) { element.WriteTo(writer); writer.Flush(); memoryStream.Position = 0; return(Encoding.UTF8.GetString(memoryStream.ToArray())); } }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <returns></returns> private static string CreateJsonString(XStreamingElement element) { using (MemoryStream memoryStream = new MemoryStream()) { using (XmlDictionaryWriter xmlDictionaryWriter = JsonReaderWriterFactory.CreateJsonWriter(memoryStream, Encoding.Unicode)) { element.WriteTo(xmlDictionaryWriter); xmlDictionaryWriter.Flush(); return(Encoding.Unicode.GetString(memoryStream.ToArray())); } } }
//[Variation(Priority = 1, Desc = "WriteTo(null)")] public void WriteToWithNull() { try { XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134"); streamElement.WriteTo((XmlWriter)null); } catch (System.ArgumentNullException) { return; } throw new TestFailedException(""); }
public void Store() { using (FileStream fs = new FileStream(this.Filename, FileMode.Create, FileAccess.Write)) { XmlWriter xw = XmlWriter.Create(fs); XStreamingElement itemsElem = new XStreamingElement("Certificates", from cert in this.Certs select cert.ToXElement()); itemsElem.WriteTo(xw); xw.Flush(); } }
//An attribute cannot be written after content. //[Variation(Priority = 1, Desc = "Add(XAttribute) After Content is Added)")] public void AddAttributeAfterContent() { try { XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134"); XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134"); streamElement.Add(contact.Attribute("type")); using (XmlWriter w = XmlWriter.Create(new MemoryStream(), null)) { streamElement.WriteTo(w); } } catch (System.InvalidOperationException) { return; } throw new TestFailedException(""); }
public void WriteXStreamingElementChildren() { var xml = "<?xml version='1.0' encoding='utf-8'?><root type='array'><item type='number'>0</item><item type='number'>2</item><item type='number'>5</item></root>".Replace('\'', '"'); var ms = new MemoryStream(); var xw = XmlWriter.Create(ms); int [] arr = new int [] { 0, 2, 5 }; var xe = new XStreamingElement(XName.Get("root")); xe.Add(new XAttribute(XName.Get("type"), "array")); var at = new XAttribute(XName.Get("type"), "number"); foreach (var i in arr) { xe.Add(new XStreamingElement(XName.Get("item"), at, i)); } xe.WriteTo(xw); xw.Close(); Assert.AreEqual(xml, new StreamReader(new MemoryStream(ms.ToArray())).ReadToEnd(), "#1"); }
public void WriteToWithNull() { XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134"); Assert.Throws <ArgumentNullException>(() => streamElement.WriteTo((XmlWriter)null)); }