For anyone who's using ASP.NET MVC, I thought I'd share my code that I used to build the xml response.
I added this to my regular MVC controller and returned an ActionResult. I would have used WebAPI, but my API controllers return only JSON by design. JuiceBox requires xml.
I learned from Emi's post above, but I use LinqToXml's XElement and XDocument to build the xml which is generally safer as far as creating valid xml.
List<XElement> elements = new List<XElement>();
foreach (var photo in listing.Photos)
{
XElement xElement = new XElement("image",
new XAttribute("imageURL", photo.Url),
new XAttribute("thumbURL", photo.ThumbnailUrl),
new XAttribute("linkURL", photo.Url),
new XAttribute("linkTarget", "_blank"));
if (!string.IsNullOrEmpty(photo.Caption))
xElement.Add(new XElement("caption", photo.Caption));
elements.Add(xElement);
}
using (MemoryStream stream = new MemoryStream())
{
XDocument xDocument = new XDocument(
new XElement("juiceboxgallery", new XAttribute("galleryTitle", listing.Headline), elements));
xDocument.Declaration = new XDeclaration("1.0", "utf-8", "true");
xDocument.Save(stream);
stream.Seek(0, SeekOrigin.Begin);
var response = Encoding.UTF8.GetString(stream.ToArray());
Response.ContentType = "application/xml";
return Content(response);
}