Version 9 (modified by 14 years ago) ( diff ) | ,
---|
S3XRC | S3XML | S3 RESTful API
S3XML - XML/JSON Format
S3XML is the generic data format used by S3 to export and import data.
Typically, S3XML would not be used for data exchange directly (though it could be used), but as source/target format for On-the-fly Transformation using XSLT stylesheets. Through this mechanism it is possible to support a variety of XML and JSON formats, and even CSV formats for data exchange.
XML Format
These can be converted using XSLT Stylesheets.
Document Structure
S3XML defines 4 element types:
s3xml
Parent elements | none (root element) |
Child elements | resource |
Contents | empty |
resource
Parent elements | s3xml, resource, reference |
Child elements | resource |
Contents | empty |
data
Parent elements | resource |
Child elements | none (leaf element) |
Contents | Text |
Represents the value of a single field in the record.
Attributes:
Name | Type | Description | mandatory? |
field | string | the field name in the record | yes |
value | JSON value | the native field value | no |
url | URL | the URL to download the contents from* | no |
filename | filename | the filename of the attached contents* | no |
The text node in the data
element provides a human-readable representation of the field value. If this representation is different from the original value in the database, then the original value must be provided by the value attribute.
(*) If the field is for file upload, a url
attribute should be provided to specify the location of the file. The importer will try to download and store the file (file transfer) from that URL (pull). It is also possible to send the file with the HTTP request - in this case the filename
must be specified instead of url
(push). The push variant for uploads is meant for peers which do not support pulling for some reason (e.g. mobile phones). Normal servers would always provide a URL for download in order to allow the consuming site decide which files to download and when (saves bandwidth).
reference
Parent elements | resource |
Child elements | resource |
Contents | Text |
Example
<s3xml> <resource <-- a record in the database --> created_on="2009-10-02 08:55:11" <-- date/time when the record was created --> modified_on="2009-10-02 08:56:03" <-- date/time when the record was last modified --> uuid="6e6e76dc-8ed7-408c-bb09-54476e3944ae" <-- UUID of the record (if present in DB) --> created_by="None" <-- Author --> modified_by="Dominic" <-- Last Author --> name="pr_person"> <-- Resource Name --> <reference <-- Reference Field (foreign key) in the record --> field="pr_pe_id" <-- Field name --> resource="pr_pentity" <-- Name of the referenced resource --> uuid="6e6e76dc-8ed7-408c-bb09-54476e3944ae"/> <-- UUID of the referenced entry --> <data field="pr_pe_label">730421</data> <-- A field in the record --> <data field="first_name">Dominic</data> <data field="middle_name"/> <data field="last_name">König</data> <data field="preferred_name"/> <data field="local_name"/> <data field="opt_pr_gender" value="3">male</data> <data field="opt_pr_age_group" value="5">Adult (21-50)</data> <data field="email">dominic@nursix.org</data> <data field="mobile_phone"/> <data field="date_of_birth">1973-04-21</data> <data field="opt_pr_nationality" value="65">Germany</data> <data field="opt_pr_country" value="167">Sweden</data> <data field="opt_pr_religion" value="1">none</data> <data field="opt_pr_marital_status" value="3">married</data> <data field="occupation">Nurse</data> <data field="comment"/> <resource <-- A sub-resource (joined resource) of the record --> created_on="2009-10-02 11:34:34" modified_on="2009-10-02 11:34:34" uuid="89217054-3c10-4f5d-959a-420254243498" name="pr_address"> <data field="opt_pr_address_type" <-- field name --> value="1"> <-- original value in the database --> Home Address <-- value represented for human readability --> </data> <data field="co_name"/> <data field="street1">Lundgatan</data> <data field="street2"/> <data field="postcode">38031</data> <data field="city">Läckeby</data> <data field="state"/> <data field="opt_pr_country" value="167">Sweden</data> <data field="lat">56.78042</data> <data field="lon">16.27914</data> <data field="comment"/> </resource> </resource> </s3xml>
- UUID - how we handle Unique IDs for records across heterogeneous systems
JSON Format
The data structure of the native S3JSON format is equivalent to the XML format (=element trees) - except that markup elements are represented by prefixes:
{ "@domain": "yana", // Server name "@url": "http://127.0.0.1:8000/eden" // Server URL "$_pr_person": { // Resource, prefix: $_ "@uuid": "44fc762e-02df-44e0-8bd1-9b58e3132894", // Resource attribute, prefix: @ "@url": "http://127.0.0.1:8000/eden/pr/person/1", "@created_on": "2009-11-16 22:33:35", "@created_by": "None", "@modified_on": "2009-11-19 21:32:19", "@modified_by": "Dominic", "first_name": "Dominic", // Data field, no prefix "last_name": "K\u00f6nig", "email": "dominic@nursix.org", "opt_pr_age_group": {"@value": "1", "$": "unknown"}, // Data field with textual representation: "opt_pr_religion": {"@value": "1", "$": "none"}, // @value=Value, $=TextualRepresentation "opt_pr_gender": {"@value": "1", "$": "unknown"}, "opt_pr_nationality": {"@value": "999", "$": "unknown"}, "opt_pr_country": {"@value": "999", "$": "unknown"}, "opt_pr_marital_status": {"@value": "1", "$": "unknown"}, "$k_pr_pe_id": { // External Reference (Key), prefix: $k_ "@resource": "pr_pentity", // Key resource name "@uuid": "a2a945bd-4f43-41da-bcdb-e2e638a987ea", // UUID of the key record "$": "Dominic K\u00f6nig [no label] (Person)" // Textual representation of the reference }, "$_pr_presence": { // Joined Resource (Component): "@uuid": "14af2751-7277-4e90-b42b-0d0430684561", // appears as component within the resource "@created_on": "2009-11-19 19:42:46", "@modified_on": "2009-11-19 19:42:46" "@url": "http://127.0.0.1:8000/eden/pr/person/1/presence/1", "opt_pr_presence_condition": {"@value": "4", "$": "Found"}, "time": {"@value": "2009-11-19 18:42:00 +0000", "$": "2009-11-19 20:42:00"}, "$k_reporter": { "@resource": "pr_person", "@uuid": "44fc762e-02df-44e0-8bd1-9b58e3132894", "$": "Dominic K\u00f6nig" }, } }, }
JSON format characteristics:
- The JSON output contains _no_ whitespace between elements, it's just added here by hand for better readability
- The outermost structure is always a JSON object (not a list)
- All data is represented as strings (for security reasons)
- If @value is sent for a field, it overrides the element text ($) at import
- however, the use of @value is not mandatory, data can simply be placed instead of element text
- Note that there is no automatic data encoding: data must be sent in DB-encoded format
- @resource, @name and @uuid attributes are mandatory at input, other attributes can be omitted
- Multiple records of the same resource will be aggregated as lists like:
{ $_my_resource: [ { // record1 of my_resource } { // record2 of my_resource } ] }