diff --git a/src/Twilio/TwiML/TwiML.cs b/src/Twilio/TwiML/TwiML.cs index f69e71668..ec625992d 100644 --- a/src/Twilio/TwiML/TwiML.cs +++ b/src/Twilio/TwiML/TwiML.cs @@ -154,6 +154,17 @@ protected virtual XNode ToXml() return elem; } + + /// + /// Generate XDocument from TwiML object + /// + public XDocument ToXDocument() + { + var declaration = new XDeclaration("1.0", "utf-8", null); + var elem = this.ToXml(); + var document = new XDocument(declaration, elem); + return document; + } /// /// Generate XML string from TwiML object @@ -161,10 +172,7 @@ protected virtual XNode ToXml() /// Change generated string format. public string ToString(SaveOptions formattingOptions = SaveOptions.None) { - var declaration = new XDeclaration("1.0", "utf-8", null); - var elem = this.ToXml(); - - var document = new XDocument(declaration, elem); + var document = this.ToXDocument(); var writer = new Utf8StringWriter(); document.Save(writer, formattingOptions); return writer.GetStringBuilder().ToString();