Creating new data object

Please import the Client API test data for the following example. This module provides some schemas and example data. We will now create our first data object in the Information Server.

using System;
using System.Xml.Linq;
using Onion.Client;

class Program
  static void Main(string[] args)
    using (var session = new OnionSession("ipc://", "admin", "admin"))
      IDataObject contacts = session.Repository.Lookup("Client API Testdata", "1. Contacts");

      XNamespace xsi = "";

      var el = new XElement("person",
        new XAttribute(XNamespace.Xmlns + "xsi", xsi),
        new XAttribute(xsi + "schemaLocation", ""),
        new XAttribute("gender", "male"),
        new XElement("address",
          new XElement("street", "Musterstraße 123"),
          new XElement("zipCode", "12345"),
          new XElement("city", "Musterhausen")
      IDataObject newContact = contacts.Children.Create("Max Mustermann", el.ToString());

      Console.WriteLine(String.Format("New data object {0} created on {1}.", newContact.Id, newContact.DateCreated));

In, each data object is located at a hierarchical position with a structural identifier. We use “IDataRepository.Lookup” to find a data object using a path indication. The interface “IDataObjectChildrenCollection” offers the method “Create” in order to create a new data object. It supplies the new data object as the result. Executing the example should lead to a similar result.

New data object 610 created on 25.07.2010 12:00:11.

The new data object can then be looked at in the Editor.