Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Creating Enhanced Presence Data Classes from the XML Schemas

You can create C# code from the schemas using XSD.EXE.

For example, the schema for the presence note data types in the Unified Communications Enhanced Presence Schemas is defined in the note.xsd file. According to this schema, the presence note is represented by a <note> element that consists of a set of sub elements as well as the majorVersion, minorVersion, and a possible custom attribute (<anyAttribute>). The sub elements of the <note> element are defined to consist of the following:

  • One or more <body> elements.
  • An optional set of zero or more <ct:delimiter> and <#any> element pairs and the optional set is closed by a <ct:end> element. <ct:delimiter> and <ct:end> are defined in the commontypes.xsd file.
  • An optional <ct:extension> element. <ct:extension> is defined in commontypes.xsd.

The <body> element itself contains the following attributes:

  • type, indicating the type of the note.
  • LCID, specifying the language ID of the note.
  • uri, identifying the publisher of the note.
  • startTime, showing the starting time of the note publication.
  • endTime, showing the ending time of the note publication.

For the complete presence note schema specification, see the note.xsd and commontypes.xsd files.

Because note.xsd makes references to the elements imported from commontypes.xsd, both files must be specified in order to generate the .NET Framework classes for the presence note.

The following command demonstrates how to generate C# classes for presence note types:

Xsd.exe /c note.xsd commontypes.xsd

Here, the command flag /c is a shorthand for /class. It indicates that the transformation produces .NET Framework classes from the specified XML Schema Definition (xsd) files. The output is a C# source file and the name of the output file is note_commontypes.cs. To generate Visual Basic code, use the following command:

Xsd.exe /c /l:VB note.xsd commontypes.xsd

Here, the command parameter /l is a shorthand for /language. The value of this parameter indicates the programming language of the generated source code. In this example, the generated source code is in Visual Basic. The name of the output file from the previous command example becomes note_commontypes.vb.

To assign a namespace for the generated source code, use the following command:

Xsd.exe /c /n:EnhancedPresence.Note note.xsd commontypes.xsd

Here the command parameter /n is a shorthand for /namespace and the value of this parameter, EnhancedPresence.Note, is the C# code namespace of the generated source code.

This procedure can be used with other schema files to generate additional enhanced presence data classes:

Xsd.exe /c /n:EnhancedPresence.Calendata calendardata.xsd calendardatatypes.xsd commontypes.xsd
xsd.exe /c /n:EnhancedPresence.ContactCard contactcard.xsd commontypes.xsd
xsd.exe /c /n:EnhancedPresence.Device device.xsd commontypes.xsd
xsd.exe /c /n:EnhancedPresence.Note note.xsd commontypes.xsd
xsd.exe /c /n:EnhancedPresence.Options options-Alerts.xsd options-OtherOptions.xsd options-RccOptions.xsd options-UserInformation.xsd commontypes.xsd
xsd.exe /c /n:EnhancedPresence.Service service.xsd commontypes.xsd
xsd.exe /c /n:EnhancedPresence.State state.xsd commontypes.xsd 
xsd.exe /c /n:EnhancedPresence.UserProperties userProperties.xsd commontypes.xsd

After the source files are created, you can also build a .NET Framework assembly using the following command:

csc /out:enhancedPresence.dll /t:library /r:system.dll contactcard_commontypes.cs calendardata_calendardatatypes_commontypes.cs device_commontypes.cs note_commontypes.cs options-Alerts_options-OtherOptions_options-RccOptions_options-UserInformation_commontypes.cs service_commontypes.cs state_commontypes.cs userProperties_commontypes.cs

The output of this command is enhancedPresence.dll, a .NET Framework library.

With the assembly or the source files, you can now begin to instantiate the presence data classes, initialize the objects, and generate their corresponding XML representations using XML serialization supported by .NET Framework.

Show:
© 2014 Microsoft. All rights reserved.