c# - XML file loaded as a string -
i have noticed code wrote few years , whilst thinking optimizations thought maybe area improved. have following:
var xml = new stringbuilder(""); foreach (var product in products) { xml.append(product.asxml()); // gives xml string. } return string.format("<products>{0}</products>", xml);
the xml string large number of products in database increase, wondering if there better way this.
jd
i use linq xml link
you try this:
var prod = new list<string>(); prod.add("apples"); prod.add("oranges"); var doc = new xelement("product"); foreach(string p in prod){ doc.add(new xelement("products", p)); } debug.writeline(doc.tostring());
outputs this
<product> <products>apples</products> <products>oranges</products> </product>
this mean no mucking around strings.
cheers
iain
Comments
Post a Comment