Storing XML files


public void StoreXml(string host, string filename, string culture, string token){

	var client = new RestClient(host + "/Congree/api/AuthoringMemory/v1/ImportXml?lang=" + culture);
	var request = new RestRequest(Method.POST);
	request.AddHeader("Content-Type", "multipart/form-data");
	request.AddHeader("Authorization", "Bearer " + token);
	
 	request.AddHeader("Content-Type", "multipart/form-data");
    request.AlwaysMultipartFormData = true;
    request.AddFile("file", filename,  ParameterType.RequestBody);
	IRestResponse response = client.Execute(request);

}
ParameterDescription
hostThe address of the server hosting Congree Authoring Server
filenameThe name of the file to be imported. The file must be either a valid file, e.g. the referenced DTD must be accessible or a well-formed XML file.
cultureThe code of the language the imported file is written in.
tokenThe Bearer token acquired during the authentication.

While importing documents into the Authoring Memory it is possible to assign attributes to the import. Those attributes can later be used for different purpose like filtering them by certain usage areas or identifying them by an ID coming from a CMS. The attributes to be used must have beend defined in Congree's Authoring Memory first (Defining Attributes).

To add attributes you just need to add another parameter to the request specifying the attribute(s) you want to assign. The general syntax looks like shown below:

[
  {
    "Name": [attribute name],
    "Values": [
      [attribute value]
    ]
  }
]
PropertyDescription
attribute nameThe name of the attribute you want to assign.
attribute valueA string array containg the value(s) of the attribute

Let's assume you want to assign the attribute "usageArea" with the values "Marketing" and "TechPubs" and the attribute "CMS_Id". The JSON structure will look like this:

[
  {
    "Name": "usageArea",
    "Values": [
      "Marketing",
	  "TechPubs"
    ]
  },
{
    "Name": "CMS_Id",
    "Values": [
      "Id001"
    ]
  }
]

To store the attributes along with the XML file you need to add a new request parameter to the code shown above (StoreXML).

public void StoreXml(string host, string filename, string culture, string token){
 
    var client = new RestClient(host + "/Congree/api/AuthoringMemory/v1/ImportXml?lang=" + culture);
    var request = new RestRequest(Method.POST);
    request.AddHeader("Content-Type", "multipart/form-data");
    request.AddHeader("Authorization", "Bearer " + token);
     
    request.AddHeader("Content-Type", "multipart/form-data");
    request.AlwaysMultipartFormData = true;
    request.AddFile("file", filename,  ParameterType.RequestBody);
	request.AddParameter("attributes", "[ { "Name": "usageArea", "Values": ["Marketing","TechPubs"]},{ "Name": "CMS_Id","Values": ["Id001"]}]");
    IRestResponse response = client.Execute(request);
 
}

Searching for sentences in the Authoring Memory

public void SearchSentence(string host, string ruleSet, string token, string sentence){

	var client = new RestClient(host + "/Congree/api/AuthoringMemory/v1/Search");
	var request = new RestRequest(Method.POST);
	request.AddHeader("Content-Type", "application/json");
	request.AddHeader("Accept", "application/json");
	request.AddHeader("Authorization", "Bearer " + token);
	request.AddParameter("undefined", "{ \n   \"Xml\": \" + sentence + "\",\n   \"RuleSetName\": \" + ruleSet + "\" \n }", ParameterType.RequestBody);
	IRestResponse response = client.Execute(request);
}
ParameterDescription
hostThe address of the server hosting Congree Authoring Server
ruleSetThe name of the ruleset the sentence is checked with.
tokenThe Bearer token acquired during the authentication.
sentenceA well-formed XML structure.

The request returns a JSON object that is described in the Reference Manual.