Skip to Content

Scripting Example - Return a Field as XML

This Plugin example script will return a field in your data object via the REST endpoint as XML, making it consumable by other applications and platforms. See the Configuration Notes for implementing this Plugin in Vinyl.

Example Script

#r "Newtonsoft.Json.dll"
using System;
using System.Net.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
/**
 The format of the json produced by Vinyl is:
 {
     items: [
       {
           "field1": "value",
           "field2": "value",
           "field3": "value",
           ...
       }
       ...
     ]
 }

 This plugin is grabbing the FIRST item returned (["items"][0])

 We then look for a particular field containing xml - in this case "xmlCode"

 We then return this as the xml content - discarding the rest of the message
**/
// Read the response content
var message = await Response.Content.ReadAsStringAsync();
var jobject = JObject.Parse(message);
// This is likely always the same - the first item returned
var item = jobject["items"][0];
// Change xmlCode to match the name of the field in your object:
var xmlContent = item["xmlCode"].ToString();
// Return just the xmlContent
Response.Content = new StringContent(xmlContent, null, "application/xml");

Configuration Notes

  1. When configuring the Plugin in Vinyl, use the following values:

    • Name: ReturnXmlFromJson
    • Description: Pick out xml returned from within json and return as just xml
    • Purpose: Rest Response
  2. When configuring the XMP Endpoint in Vinyl, click on Edge Case Settings and set the Endpoint Plugin Response value to ReturnXmlFromJson

  3. When configuring the REST API Web Service, set the Request Content Type value to JSON and Response Content Type to XML