public StreamingElementWriter(XmlWriter w) { _writer = w; _element = null; _attributes = new List <XAttribute>(); _resolver = new NamespaceResolver(); }
public XElement (XStreamingElement other) { if (other == null) throw new ArgumentNullException ("other"); this.name = other.Name; Add (other.Contents); }
private void WriteFile(string targetDirectory, string entityNames, XStreamingElement fileContents) { var fileContentsWithHeader = @"<?xml version=""1.0"" encoding=""utf-8""?>" + Environment.NewLine + fileContents; var path = Path.Combine(targetDirectory, entityNames + ".xml"); if (File.Exists(path)) { var existingFileContents = File.ReadAllText(path); if (existingFileContents == fileContentsWithHeader) { return; } var backupFolder = Path.Combine(targetDirectory, @"backup\"); Directory.CreateDirectory(backupFolder); var fileNumber = GetFileNumber(backupFolder, entityNames); var backupFileName = String.Format("{0}.backup-{1}.xml", entityNames, fileNumber); var backupPath = Path.Combine(backupFolder, backupFileName); File.Move(path, backupPath); } File.WriteAllText(path, fileContentsWithHeader); }
public StreamingElementWriter(XmlWriter w) { _writer = w; _element = null; _attributes = new List <XAttribute>(); _resolver = default; }
public StreamingElementWriter(XmlWriter w) { this.writer = w; this.element = null; this.attributes = new List<XAttribute>(); this.resolver = new NamespaceResolver(); }
public void ToString () { var el = new XStreamingElement ("foo", new XAttribute ("bar", "baz"), "text"); Assert.AreEqual ("<foo bar=\"baz\">text</foo>", el.ToString ()); }
public void ToStringAttributeAfterText () { var el = new XStreamingElement ("foo", "text", new XAttribute ("bar", "baz")); el.ToString (); }
/// <overloads> /// Adds the specified content as a child (or as children) to this <see cref="XContainer"/>. The /// content can be simple content, a collection of content objects, a parameter list /// of content objects, or null. /// </overloads> /// <summary> /// Adds the specified content as a child (or children) of this <see cref="XContainer"/>. /// </summary> /// <param name="content"> /// A content object containing simple content or a collection of content objects /// to be added. /// </param> /// <remarks> /// When adding simple content, a number of types may be passed to this method. /// Valid types include: /// <list> /// <item>string</item> /// <item>double</item> /// <item>float</item> /// <item>decimal</item> /// <item>bool</item> /// <item>DateTime</item> /// <item>DateTimeOffset</item> /// <item>TimeSpan</item> /// <item>Any type implementing ToString()</item> /// <item>Any type implementing IEnumerable</item> /// /// </list> /// When adding complex content, a number of types may be passed to this method. /// <list> /// <item>XObject</item> /// <item>XNode</item> /// <item>XAttribute</item> /// <item>Any type implementing IEnumerable</item> /// </list> /// /// If an object implements IEnumerable, then the collection in the object is enumerated, /// and all items in the collection are added. If the collection contains simple content, /// then the simple content in the collection is concatenated and added as a single /// string of simple content. If the collection contains complex content, then each item /// in the collection is added separately. /// /// If content is null, nothing is added. This allows the results of a query to be passed /// as content. If the query returns null, no contents are added, and this method does not /// throw a NullReferenceException. /// /// Attributes and simple content can't be added to a document. /// /// An added attribute must have a unique name within the element to /// which it is being added. /// </remarks> public void Add(object content) { if (SkipNotify()) { AddContentSkipNotify(content); return; } if (content == null) { return; } XNode n = content as XNode; if (n != null) { AddNode(n); return; } string s = content as string; if (s != null) { AddString(s); return; } XAttribute a = content as XAttribute; if (a != null) { AddAttribute(a); return; } XStreamingElement x = content as XStreamingElement; if (x != null) { AddNode(new XElement(x)); return; } object[] o = content as object[]; if (o != null) { foreach (object obj in o) { Add(obj); } return; } IEnumerable e = content as IEnumerable; if (e != null) { foreach (object obj in e) { Add(obj); } return; } AddString(GetStringValue(content)); }
public StreamingElementWriter(XmlWriter w) { this.writer = w; this.element = null; this.attributes = new List <XAttribute>(); this.resolver = new NamespaceResolver(); }
private XStreamingElement MakeItems() { int itemId = 0; var xmlItems = _collection.Items.Select( item => new XStreamingElement(Xmlns + "I", MakeItemContent(item, itemId++))); XStreamingElement items = new XStreamingElement(Xmlns + "Items", xmlItems); return items; }
public XElement(XStreamingElement other) { if (other == null) { throw new ArgumentNullException("other"); } this.name = other.Name; Add(other.Contents); }
public XElement(XStreamingElement other) { if (other == null) { throw new ArgumentNullException("other"); } this.name = other.name; base.AddContentSkipNotify(other.content); }
internal void WriteStreamingElement(XStreamingElement e) { FlushElement(); _element = e; Write(e.content); FlushElement(); _writer.WriteEndElement(); _resolver.PopScope(); }
private void AddContent(object content) { if (content != null) { XNode n = content as XNode; if (n != null) { this.AddNode(n); } else { string s = content as string; if (s != null) { this.AddString(s); } else { XStreamingElement other = content as XStreamingElement; if (other != null) { this.AddNode(new XElement(other)); } else { object[] objArray = content as object[]; if (objArray != null) { foreach (object obj2 in objArray) { this.AddContent(obj2); } } else { IEnumerable enumerable = content as IEnumerable; if (enumerable != null) { foreach (object obj3 in enumerable) { this.AddContent(obj3); } } else { if (content is XAttribute) { throw new ArgumentException(Res.GetString("Argument_AddAttribute")); } this.AddString(XContainer.GetStringValue(content)); } } } } } } }
private void Write(object content) { if (content == null) { return; } XNode n = content as XNode; if (n != null) { WriteNode(n); return; } string s = content as string; if (s != null) { WriteString(s); return; } XAttribute a = content as XAttribute; if (a != null) { WriteAttribute(a); return; } XStreamingElement x = content as XStreamingElement; if (x != null) { WriteStreamingElement(x); return; } object[] o = content as object[]; if (o != null) { foreach (object obj in o) { Write(obj); } return; } IEnumerable e = content as IEnumerable; if (e != null) { foreach (object obj in e) { Write(obj); } return; } WriteString(XContainer.GetStringValue(content)); }
public void XNameWithNamespaceConstructor() { XNamespace ns = @"http:\\www.contacts.com\"; XElement contact = new XElement(ns + "contact"); XStreamingElement streamElement = new XStreamingElement(ns + "contact"); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
//[Variation(Priority = 1, Desc = "Constructor - XStreamingElement(null)")] public void XNameAsNullConstructor() { try { XStreamingElement streamElement = new XStreamingElement(null); } catch (System.ArgumentNullException) { return; } throw new TestFailedException(""); }
//[Variation(Priority = 1, Desc = "Constructor - XStreamingElement('')")] public void XNameAsEmptyStringConstructor() { try { XStreamingElement streamElement = new XStreamingElement(" "); } catch (System.Xml.XmlException) { return; } throw new TestFailedException(""); }
private void AddContent(object content) { if (content == null) { return; } XNode n = content as XNode; if (n != null) { AddNode(n); return; } string s = content as string; if (s != null) { AddString(s); return; } XStreamingElement x = content as XStreamingElement; if (x != null) { AddNode(new XElement(x)); return; } object[] o = content as object[]; if (o != null) { foreach (object obj in o) { AddContent(obj); } return; } IEnumerable e = content as IEnumerable; if (e != null) { foreach (object obj in e) { AddContent(obj); } return; } if (content is XAttribute) { throw new ArgumentException(SR.Argument_AddAttribute); } AddString(XContainer.GetStringValue(content)); }
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"); }
internal void WriteStreamingElement(XStreamingElement e) { this.FlushElement(); this.element = e; this.Write(e.content); bool flag = this.element == null; this.FlushElement(); if (flag) { this.writer.WriteFullEndElement(); } else { this.writer.WriteEndElement(); } this.resolver.PopScope(); }
private void FlushElement() { if (this.element != null) { this.PushElement(); XNamespace ns = this.element.Name.Namespace; this.writer.WriteStartElement(this.GetPrefixOfNamespace(ns, true), this.element.Name.LocalName, ns.NamespaceName); foreach (XAttribute attribute in this.attributes) { ns = attribute.Name.Namespace; string localName = attribute.Name.LocalName; string namespaceName = ns.NamespaceName; this.writer.WriteAttributeString(this.GetPrefixOfNamespace(ns, false), localName, ((namespaceName.Length == 0) && (localName == "xmlns")) ? "http://www.w3.org/2000/xmlns/" : namespaceName, attribute.Value); } this.element = null; this.attributes.Clear(); } }
internal void WriteStreamingElement(XStreamingElement e) { FlushElement(); _element = e; Write(e.content); bool contentWritten = _element == null; FlushElement(); if (contentWritten) { _writer.WriteFullEndElement(); } else { _writer.WriteEndElement(); } _resolver.PopScope(); }
private void FlushElement() { if (_element != null) { PushElement(); XNamespace ns = _element.Name.Namespace; _writer.WriteStartElement(GetPrefixOfNamespace(ns, true), _element.Name.LocalName, ns.NamespaceName); foreach (XAttribute a in _attributes) { ns = a.Name.Namespace; string localName = a.Name.LocalName; string namespaceName = ns.NamespaceName; _writer.WriteAttributeString(GetPrefixOfNamespace(ns, false), localName, namespaceName.Length == 0 && localName == "xmlns" ? XNamespace.xmlnsPrefixNamespace : namespaceName, a.Value); } _element = null; _attributes.Clear(); } }
internal void AddContentSkipNotify(object content) { if (content == null) return; XNode n = content as XNode; if (n != null) { AddNodeSkipNotify(n); return; } string s = content as string; if (s != null) { AddStringSkipNotify(s); return; } XAttribute a = content as XAttribute; if (a != null) { AddAttributeSkipNotify(a); return; } XStreamingElement x = content as XStreamingElement; if (x != null) { AddNodeSkipNotify(new XElement(x)); return; } object[] o = content as object[]; if (o != null) { foreach (object obj in o) AddContentSkipNotify(obj); return; } IEnumerable e = content as IEnumerable; if (e != null) { foreach (object obj in e) AddContentSkipNotify(obj); return; } AddStringSkipNotify(GetStringValue(content)); }
public void WriteAccounts_creates_a_backup_and_overwrites_Account_file_if_it_has_changed() { _fileWriter.WriteAccountFile(TestDirectory); var originalTimestamp = File.GetLastWriteTimeUtc(_expectedAccountPath); Thread.Sleep(10); var modifiedAccountXml = new XStreamingElement("test", "someDifferentContent"); _accountRepository.EmitXml().Returns(modifiedAccountXml); _fileWriter.WriteAccountFile(TestDirectory); var timestampAfterSecondWrite = File.GetLastWriteTimeUtc(_expectedAccountPath); Assert.AreNotEqual(originalTimestamp, timestampAfterSecondWrite); var backupPath = Path.Combine(TestDirectory, @"backup\", "accounts.backup-1.xml"); Assert.IsTrue(File.Exists(backupPath)); Assert.AreEqual(_accountXml.ToString(), File.ReadAllText(backupPath)); Assert.AreEqual(originalTimestamp, File.GetLastWriteTimeUtc(backupPath)); }
private XStreamingElement MakeCxmlTree() { XStreamingElement root = new XStreamingElement(Xmlns + "Collection", MakeCollectionContent()); return root; }
// // Summary: // Initializes a new instance of the System.Xml.Linq.XElement class from an // System.Xml.Linq.XStreamingElement object. // // Parameters: // other: // An System.Xml.Linq.XStreamingElement that contains unevaluated queries that // will be iterated for the contents of this System.Xml.Linq.XElement. public XElement(XStreamingElement other) { Contract.Requires(other != null); }
public PropertyElement(XStreamingElement other) : base(other) { }
public void XNameAndNullObjectConstructor() { XStreamingElement streamElement = new XStreamingElement("contact", null); Assert.Equal("<contact />", streamElement.ToString()); }
public void XStreamingElementSave_SaveOptions() { string markup = "<e a=\"value\"> <!--comment--> <e2> <![CDATA[cdata]]> </e2> <?pi target?> </e>"; try { XElement e = XElement.Parse(markup, LoadOptions.PreserveWhitespace); XStreamingElement e2 = new XStreamingElement(e.Name, e.Attributes(), e.Nodes()); e2.Save(_fileName, SaveOptions.DisableFormatting); } finally { Assert.True(File.Exists(_fileName)); Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + markup, File.ReadAllText(_fileName)); File.Delete(_fileName); } }
public XElement(XStreamingElement source) { this.name = source.Name; Add(source.Contents); }
private XStreamingElement MakeItems() { XStreamingElement items = new XStreamingElement(Xmlns + "Items", MakeItemsContent()); return items; }
public void Add(object content) { if (base.SkipNotify()) { this.AddContentSkipNotify(content); } else if (content != null) { XNode n = content as XNode; if (n != null) { this.AddNode(n); } else { string s = content as string; if (s != null) { this.AddString(s); } else { XAttribute a = content as XAttribute; if (a != null) { this.AddAttribute(a); } else { XStreamingElement other = content as XStreamingElement; if (other != null) { this.AddNode(new XElement(other)); } else { object[] objArray = content as object[]; if (objArray != null) { foreach (object obj2 in objArray) { this.Add(obj2); } } else { IEnumerable enumerable = content as IEnumerable; if (enumerable != null) { foreach (object obj3 in enumerable) { this.Add(obj3); } } else { this.AddString(GetStringValue(content)); } } } } } } } }
public void XNameAndXElementObjectConstructor() { XElement contact = new XElement("contact", new XElement("phone", "925-555-0134")); XStreamingElement streamElement = new XStreamingElement("contact", contact.Element("phone")); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
private void Write(object content) { if (content != null) { XNode n = content as XNode; if (n != null) { this.WriteNode(n); } else { string s = content as string; if (s != null) { this.WriteString(s); } else { XAttribute a = content as XAttribute; if (a != null) { this.WriteAttribute(a); } else { XStreamingElement e = content as XStreamingElement; if (e != null) { this.WriteStreamingElement(e); } else { object[] objArray = content as object[]; if (objArray != null) { foreach (object obj2 in objArray) { this.Write(obj2); } } else { IEnumerable enumerable = content as IEnumerable; if (enumerable != null) { foreach (object obj3 in enumerable) { this.Write(obj3); } } else { this.WriteString(XContainer.GetStringValue(content)); } } } } } } } }
private XStreamingElement MakeFacetCategories() { XStreamingElement facetCats = new XStreamingElement(Xmlns + "FacetCategories", MakeFacetCategoriesContent()); return facetCats; }
private static void SaveLow(Dictionary<string, object> paraDic) { try { //新建一个xml文档类 XDocument xdoc = new XDocument(); //可以增加注释 xdoc.Add(new XComment("增加注释测试")); //增加内容 XStreamingElement rootXE = new XStreamingElement("root"); Jewelry je = paraDic["context"] as Jewelry; //解析内容 rootXE.Add(new XElement("guid", je.Guid.ToString())); rootXE.Add(new XElement("image", helper.ImageToBase64(je.Image))); rootXE.Add(new XElement("totalweight", je.TotalWeight.ToString())); rootXE.Add(new XElement("jadeweight", je.JadeWeight.ToString())); rootXE.Add(new XElement("goldweight", je.GoldWeight.ToString())); rootXE.Add(new XElement("processfee", je.ProcessFee.ToString())); rootXE.Add(new XElement("otherfee", je.OtherFee.ToString())); rootXE.Add(new XElement("totalprice", je.TotalPrice.ToString())); xdoc.Add(rootXE); string sql = string.Format("insert into {0} Values('{1}','{2}','{3}','{4}')", "detail", je.Guid.ToString(), xdoc.ToString(), System.DateTime.Now, System.DateTime.Now); SQLiteConnection conn = new SQLiteConnection(@"Data Source=c:/xhz/ms.db;"); //SQLiteConnection conn = new SQLiteConnection(@"Data Source=DB/ms.db;"); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(sql, conn); int i = cmd.ExecuteNonQuery(); System.Windows.MessageBox.Show(i.ToString()); conn.Close(); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message.ToString()); } finally { } }
public XElement (XStreamingElement other) { this.name = other.Name; Add (other.Contents); }
public StreamingElementWriter(XmlWriter w) { _writer = w; _element = null; _attributes = new List<XAttribute>(); _resolver = new NamespaceResolver(); }
/// <summary> /// Initializes an XElement object from an <see cref="XStreamingElement"/> object. /// </summary> /// <param name="other"> /// The <see cref="XStreamingElement"/> object whose value will be used /// to initialize the new element. /// </param> public XElement(XStreamingElement other) { if (other == null) throw new ArgumentNullException("other"); name = other.name; AddContentSkipNotify(other.content); }
public XElement(XStreamingElement other) { this.name = other.Name; Add(other.Contents); }
public DocumentElement(XStreamingElement other) : base(other) { }
public void XLinq32() { XDocument customers = XDocument.Load(dataPath + "nw_customers.xml"); XDocument orders = XDocument.Load(dataPath + "nw_orders.xml"); XStreamingElement summary = new XStreamingElement("Summary", new XAttribute("Country", "Sweden"), new XStreamingElement("SwedishCustomerOrders", GetSwedishCustomerOrders(customers, orders)), new XStreamingElement("Orders", GetSwedishFreightProfile(orders))); Console.WriteLine(summary); //DML operation, which adds a new order for customer BERGS freight > 250 AddNewOrder(orders); Console.WriteLine("****XStreaming Output after DML reflects new order added!!****"); Console.WriteLine(summary); }
public XElement (XStreamingElement source) { this.name = source.Name; Add (source.Contents); }