Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ToXDocument method to TwiML #649

Merged
merged 2 commits into from
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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