3 .\" (C) Lluis Sanchez Gual (lluis@ximian.com)
7 genxs \- Mono's Xml Serializer Generator
11 configurationFile [destinationFolder]
14 is a tool for generating custom XML serialization writers and readers for
18 is configuration file which specifies several
19 information, such as the class for which to generate the reader and writer, the
20 name and namespace of the classes to generate, and a collection of hooks to
21 apply. By using hooks it is possible to customize the
22 behavior of the serializer without needing to modify the generated file, so you
23 can safely regenerate it if the source class is modified.
26 specifies the folder where the files will be generated.
29 This tool only runs in the Mono runtime, since it uses some internal
30 classes not available in other runtimes.
31 .SH CONFIGURATION FILE FORMAT
32 The configuration file is an xml document based on the following grammar
33 ("?" means optional, "*" 0 or more):
37 <serializer class="name" assembly="name"> *
38 <reader>name</reader> ?
39 <writer>name</writer> ?
40 <namespace>name</namespace> ?
41 <outFileName>name</outFileName> ?
52 A configuration file can have multiple "serializer" elements, each of which
53 specifies the class for which to generate a serializer together with several
54 generation options. The source class is specified in the following attributes:
58 : name of the class (including namespace).
61 : assembly name. It can include the complete path.
63 Generation options are specified in child elements:
67 : name of the reader class.
70 : if "true", it does not generate reader class.
73 : name of the writer class.
76 : name of the base xml serializer class. This item is 2.0 only.
79 : name of the serializer implementation class. This item is 2.0 only.
82 : if "true", it does not generate writer class.
85 : namespace of the reader and writer classes.
88 : if "true", it generates classes as internal.
91 : name of the generated file.
94 : a list of hooks to apply to the reader.
97 : a list of hooks to apply to the writer.
99 Using hooks you can customize the behavior of readers and writers.
100 A hook specification follows this grammar:
105 <typeName>name</typeName> ?
106 <typeAttribute>name</typeAttribute> *
107 <typeMember>name</typeMember> ?
109 <replace>source code</replace> ?
110 <insertBefore>source code</insertBefore> ?
111 <insertAfter>source code</insertAfter> ?
115 The "type" attribute specifies the context in which the hook is applied. It can
116 be one of the following:
120 : hook is applied where attributes are serialized/deserialized.
123 : hook is applied where elements are serialized/deserialized.
126 : hook is applied where unknown attributes are processed.
129 : hook is applied where unknown elements are processed.
132 : hook is applied where a member is serialized/deserialized.
135 : hook is applied for the whole type.
137 The "select" element specifies the classes and members to which the hook has
138 to be added. It can contain the following elements:
142 : the class with that name will be selected (must include namespace)
145 : all classes which have that attribute applied will be selected (specify the
146 full attribute class name, including namespace). Several attribute names can be
150 : name of the class member for which the hook must be added.
152 The hook source code can be specified using any of the following elements:
156 : the provided source code will replace all serialization/deserialization
157 operations in the hook context.
160 : the source code will be added before the hook context.
163 : the source code will be added after the hook context.
165 When writing the code for a hook you can use some special variables that are
166 defined during the code generation process. The variables are the following:
170 name of the class being generated, without namespace.
173 full name of the class being generated, including namespace.
176 the object being serialized or deserialized. When using a replace
177 reader hook of type "type", the hook code must assign the deserialized object
181 name of the element of the object being serialized/deserialized.
184 namespace of the element of the object being serialized/deserialized.
187 name of the member being serialized/deserialized. Only valid in the "member"
190 The following example adds a call to a Validate method after the deserialization
196 System.Xml.Schema.XmlSchema.Validate$TYPE ($OBJECT);
201 This example specifies the code to be used to deserialize the XmlSchema class:
206 <typeName>System.Xml.Schema.XmlSchema</typeName>
209 $OBJECT = System.Xml.Schema.XmlSchema.Read (Reader, null);
214 That one specifies the code to be used to read XmlSchema instances:
219 <typeName>System.Xml.Schema.XmlSchema</typeName>
221 <replace>$OBJECT.Write (Writer);</replace>
225 With this two hooks the serializer will print some information when serializing
231 <typeName>MyNamespace.MyClass</typeName>
233 <insertBefore>Console.WriteLine ("Serializing MyClass");</replace>
234 <insertAfter>Console.WriteLine ("MyClass serialized");</insertAfter>
238 <typeName>MyNamespace.MyClass</typeName>
241 Console.WriteLine ("Serialized member $MEMBER");
246 This hook writes an additional element for all types that have the custom
247 attribute "MyAttribute":
250 <hook type="elements">
252 <typeAttribute>MyNamespace.MyAttribute</typeAttribute>
255 Writer.WriteStartElement ("privateData");
256 Writer.WriteString ($OBJECT.PrivateData);
257 Writer.WriteEndElement ();
261 .SH CONFIGURATION FILE EXAMPLE
262 This is the configuration file used to generate the serializer for ServiceDescription:
266 <serializer class="System.Web.Services.Description.ServiceDescription" assembly="System.Web.Services">
267 <reader>ServiceDescriptionReaderBase</reader>
268 <writer>ServiceDescriptionWriterBase</writer>
269 <namespace>System.Web.Services.Description</namespace>
270 <outFileName>ServiceDescriptionSerializerBase.cs</outFileName>
272 <hook type="unknownElement">
274 <typeAttribute>System.Web.Services.Configuration.XmlFormatExtensionPointAttribute</typeAttribute>
276 <replace>ServiceDescription.ReadExtension (Reader, $OBJECT);</replace>
280 <typeName>System.Xml.Schema.XmlSchema</typeName>
282 <replace>$OBJECT = System.Xml.Schema.XmlSchema.Read (Reader, null);</replace>
286 <hook type="elements">
288 <typeAttribute>System.Web.Services.Configuration.XmlFormatExtensionPointAttribute</typeAttribute>
290 <insertBefore>ServiceDescription.WriteExtensions (Writer, $OBJECT);</insertBefore>
294 <typeName>System.Xml.Schema.XmlSchema</typeName>
296 <replace>$OBJECT.Write (Writer);</replace>
303 Lluis Sanchez Gual (lluis@ximian.com)
306 GenXS is released under the terms of the GNU GPL.
309 mono(1), mcs(1), sgen(1)