Most efficient way for write only XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Thielen

    #1

    Most efficient way for write only XML

    Hi;

    If I am creating an XML file, what is the most efficient way to create it?
    All I can see is creating an XmlDocument, building it up, then writing it to
    a Stream. But that means I have the entire DOM sitting in memory when I have
    no need for it.

    ???

    --
    thanks - dave
  • Derek Harmon

    #2
    Re: Most efficient way for write only XML

    "David Thielen" <thielen@nospam .nospam> wrote in message news:D8E580D3-551F-4DF1-BB3F-9D89689BFA70@mi crosoft.com...[color=blue]
    > If I am creating an XML file, what is the most efficient way to create it?[/color]

    Clearly the winner would be XmlWriter (again, XmlWriter.Creat e( ) with a
    suitable XmlWriterSettin gs profile in .NET 2.0, or XmlTextWriter will fit the
    bill in many .NET 1.x scenarios.) It allows an application to emit XML serially
    such as in the following example:

    writer.WriteSta rtElement( "message");
    writer.WriteSta rtElement( "nested");
    writer.WriteEle mentString( "Hello World!");
    writer.WriteEnd Element( ); // nested.
    writer.WriteEnd Element( ); // message.

    to produce the simple XML document:

    <message>
    <nested>Hello World!</nested>
    </message>

    (Note that any indenting is a function of the Indentation/Indent property on your
    XmlTextReader or XmlWriterSettin gs.)

    If the tree-like construction of XmlDocument is closer to your information model
    then it doesn't need to be whistfully disregarded. The close match and simplicity
    may save you performance elsewhere. However, if you're dealing with large
    documents that can't be decomposed easily than you're right about the expense
    incurred for having the tree build-up like that.


    Derek Harmon


    Comment

    • David Thielen

      #3
      Re: Most efficient way for write only XML

      Again, thank you

      --
      thanks - dave


      "Derek Harmon" wrote:
      [color=blue]
      > "David Thielen" <thielen@nospam .nospam> wrote in message news:D8E580D3-551F-4DF1-BB3F-9D89689BFA70@mi crosoft.com...[color=green]
      > > If I am creating an XML file, what is the most efficient way to create it?[/color]
      >
      > Clearly the winner would be XmlWriter (again, XmlWriter.Creat e( ) with a
      > suitable XmlWriterSettin gs profile in .NET 2.0, or XmlTextWriter will fit the
      > bill in many .NET 1.x scenarios.) It allows an application to emit XML serially
      > such as in the following example:
      >
      > writer.WriteSta rtElement( "message");
      > writer.WriteSta rtElement( "nested");
      > writer.WriteEle mentString( "Hello World!");
      > writer.WriteEnd Element( ); // nested.
      > writer.WriteEnd Element( ); // message.
      >
      > to produce the simple XML document:
      >
      > <message>
      > <nested>Hello World!</nested>
      > </message>
      >
      > (Note that any indenting is a function of the Indentation/Indent property on your
      > XmlTextReader or XmlWriterSettin gs.)
      >
      > If the tree-like construction of XmlDocument is closer to your information model
      > then it doesn't need to be whistfully disregarded. The close match and simplicity
      > may save you performance elsewhere. However, if you're dealing with large
      > documents that can't be decomposed easily than you're right about the expense
      > incurred for having the tree build-up like that.
      >
      >
      > Derek Harmon
      >
      >
      >[/color]

      Comment

      Working...