Skip to content

Commit

Permalink
Add ToXDocument method to TwiML (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swimburger authored Nov 16, 2022
1 parent a2c3d20 commit dd6e56e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Twilio/TwiML/TwiML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,25 @@ protected virtual XNode ToXml()

return elem;
}

/// <summary>
/// Generate XDocument from TwiML object
/// </summary>
public XDocument ToXDocument()
{
var declaration = new XDeclaration("1.0", "utf-8", null);
var elem = this.ToXml();
var document = new XDocument(declaration, elem);
return document;
}

/// <summary>
/// Generate XML string from TwiML object
/// </summary>
/// <param name="formattingOptions"> Change generated string format. </param>
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();
Expand Down

0 comments on commit dd6e56e

Please sign in to comment.