Populating a Topic Map With Data |
Top Previous Next |
The main use for the client is to create topic map data, e.g. topics, topic properties and associations. The following example shows how to create topic map data. Notice how it uses the subject identifiers (from the SchemaConstants class) for types and not the schema objects.
/// <summary> /// Populates the topic map with two topics and an association between them /// </summary> /// <param name="tmUri">The web address of the topic map to be populated</param> /// <returns>The web address of the person topic created</returns> private static Uri CreatePerson(Uri tmUri) { // create a topic map service client and retrieve the specified topic map var client = new TopicMapServiceClient(); var tm = client.GetTopicMap(tmUri);
// create a new topic with a single label and a subject identifier var gra = tm.CreateTopic("graham", "en", new Uri("http://www.networkedplanet.com/people/gra"));
// set the type on the topic gra.AddType(new Uri(SchemaConstants.Person));
// add an age and description property gra.AddProperty(new Uri(SchemaConstants.Age), new Uri(OccurrenceDataTypes.Int), 23); gra.AddProperty(new Uri(SchemaConstants.Description), new Uri(OccurrenceDataTypes.String), "Graham Moore is director of Networked Planet");
// create the topic networkedplanet var np = tm.CreateTopic("networked planet", "en", new Uri("http://www.networkedplanet.com/companies/networkedplanet")); np.AddType(new Uri(SchemaConstants.Company));
// create an associatin between graham and networked planet tm.CreateAssociation(new Uri(SchemaConstants.WorksFor), gra.WebAddress, new Uri(SchemaConstants.Employee), np.WebAddress, new Uri(SchemaConstants.Employer));
// save all the changes to the topic map tm.SaveChanges(); return gra.WebAddress; } |