1

Why does XmlWriter's create methods have output parameters?

For example (from MSDN)

public static XmlWriter Create(
    StringBuilder output,
    XmlWriterSettings settings
)

output 
  Type: System.Text.StringBuilder 
  The StringBuilder to which to write to.
  Content written by the XmlWriter is appended to the StringBuilder.

Why doesn't create not take the StringBuilder and instead of Flush have toString or toStream or toStringBuilder if thats whats really wanted.

I'm not asking how to use XmlWriter, I'm trying to understand the reasoning why it was constructed this way. I assume there is a reason, or even it to be a known pattern with advantages and disadvantages, I'd like to know more about this

  • 1
    That's not an "output" parameter (even though it's called "output"); it's just a reference to a StringBuilder. – Robert Harvey Dec 7 '15 at 15:47
  • It's not an out parameter, but MS name it output as when Flush is called the generated xml is appended to that StringBuilder. MS naming not mine! – mattumotu Dec 7 '15 at 15:50
  • 1
    Flush doesn't flush the entire thing; it just flushes the tail end. – Robert Harvey Dec 7 '15 at 15:50
1

That's not an "output" parameter (even though it's called "output"); it's just a reference to a StringBuilder.

Why doesn't create not take the StringBuilder and instead of Flush have toString or toStream or toStringBuilder if thats whats really wanted.

Because it uses the StringBuilder during the writing process.

  • Ah so it does the writing to StringBuilder during WriteStartElement(String) (for example) rather than at the end? – mattumotu Dec 7 '15 at 15:55
  • Yes, exactly... – Robert Harvey Dec 7 '15 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.