From dd6e56eeee8616e670c90ee3636a423c3901bf36 Mon Sep 17 00:00:00 2001
From: Niels Swimberghe <3382717+Swimburger@users.noreply.github.com>
Date: Wed, 16 Nov 2022 17:54:18 -0500
Subject: [PATCH] Add `ToXDocument` method to `TwiML` (#649)
---
src/Twilio/TwiML/TwiML.cs | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
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();