Home All Groups Group Topic Archive Search About

XML => Object stored in memory?

Author
18 Dec 2008 10:33 PM
Hillbilly
Seeking insight regarding which class/control/object is optimal to write XML
into and append with additional XML while the object is in memory? The XML
must then be saved to disk and sorting by node(s) would be a real nice gift
though not necessarily required.

Author
18 Dec 2008 10:36 PM
DH
Hillbilly wrote:
> Seeking insight regarding which class/control/object is optimal to write
> XML into and append with additional XML while the object is in memory?
> The XML must then be saved to disk and sorting by node(s) would be a
> real nice gift though not necessarily required.
XmlDocument class should be helpfull.
Its in the System.Xml namespace.
DH
Are all your drivers up to date? click for free checkup

Author
18 Dec 2008 11:24 PM
Anthony Jones
"Hillbilly" <someb***@somewhere.com> wrote in message
news:eKitRCWYJHA.4272@TK2MSFTNGP03.phx.gbl...
> Seeking insight regarding which class/control/object is optimal to write
> XML into and append with additional XML while the object is in memory? The
> XML must then be saved to disk and sorting by node(s) would be a real nice
> gift though not necessarily required.

If you are using .NET 3.5 consider XDocument (System.Xml.Linq)
Node creation is IMO easier and the coding of a sort will be no problem
using a Linq query.

--
Anthony Jones - MVP ASP/ASP.NET
Author
19 Dec 2008 9:15 PM
Mr. Arnold
"Hillbilly" <someb***@somewhere.com> wrote in message
news:eKitRCWYJHA.4272@TK2MSFTNGP03.phx.gbl...
> Seeking insight regarding which class/control/object is optimal to write
> XML into and append with additional XML while the object is in memory? The
> XML must then be saved to disk and sorting by node(s) would be a real nice
> gift though not necessarily required.

You can use the StringBuilder to hold the XML in memory and append more XML.


System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append("<?xml version=\"1.0\"?>\n");
    sb.Append("<?mso-application progid=\"Excel.Sheet\"?>\n");
    sb.Append(
      "<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" ");
    sb.Append("xmlns:o=\"urn:schemas-microsoft-com:office:office\" ");
    sb.Append("xmlns:x=\"urn:schemas-microsoft-com:office:excel\" ");
    sb.Append("xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" ");
    sb.Append("xmlns:html=\"http://www.w3.org/TR/REC-html40\">\n");
    sb.Append(
      "<DocumentProperties
xmlns=\"urn:schemas-microsoft-com:office:office\">");
    sb.Append("</DocumentProperties>");
    sb.Append(
      "<ExcelWorkbook xmlns=\"urn:schemas-microsoft-com:office:excel\">\n");
    sb.Append("<ProtectStructure>False</ProtectStructure>\n");
    sb.Append("<ProtectWindows>False</ProtectWindows>\n");
    sb.Append("</ExcelWorkbook>\n");
    return sb.ToString();

You can then load the sb to a XMLdocument if you like.

xmldocument doc = new xmldocment();

doc.LoadXML(sb.ToString());

You should be able to figure out how to save it from there.

A sort on tags maybe asking too much.
Author
21 Dec 2008 4:18 AM
Hillbilly
Insightful replies received here (TU) led me to discover these documents in
Aaron Skonnard's XML Best Practices Series...

// Choosing an XML API
http://support.softartisans.com/kbview.aspx?ID=673

// Reading XML Documents
http://support.softartisans.com/kbview.aspx?ID=674


Show quoteHide quote
"Hillbilly" <someb***@somewhere.com> wrote in message
news:eKitRCWYJHA.4272@TK2MSFTNGP03.phx.gbl...
> Seeking insight regarding which class/control/object is optimal to write
> XML into and append with additional XML while the object is in memory? The
> XML must then be saved to disk and sorting by node(s) would be a real nice
> gift though not necessarily required.

Bookmark and Share